[pmwiki-users] regex for full page names with anchor suffixes

Patrick R. Michaud pmichaud at pobox.com
Thu Nov 8 14:08:19 CST 2007


On Thu, Nov 08, 2007 at 07:13:15PM +0000, Hans wrote:
> I am looking for an inclusive regex pattern for full or partial
> (without group part) page names including possible suffix for anchors,
> like the ones function TextSection() processes.
> 
> I got the following right now, but it may well miss out some pages?
> (I just added the - )
> 
> '(?>([\\w-]+\\.?[\\w-]+\\#?\\#?[\\w-]+\\.?\\.?\\#?[\\w-]*)[:=])'

First, a question:  if it's possible to use a partial pagename,
how would the system know if "xyz=..." is refering to the option 'xyz'
or to the page 'Xyz' in the current group?

One suggestion I'd have would be to use an explicit syntax
for pagename specifiers, such as brackets.  I.e.:

    (:directive  xyz=...   [Group.Abc#section]=... [xyz]=... :)

The brackets would then make it clear that the option is for
a given subtemplate as opposed to being an option for the overall
directive.  The contents of the brackets can then be passed
directly to RetrieveAuthSection().

The pattern for this would then be something like:

 '(?>(\\[.+\\]|\\w+)[:=])'

If you really want a bare option syntax for pagenames, then
I suggest keeping the pattern very simple (and possibly permissive)).
I'll space it out here for clarity:

  (?>
    (
      [-\\w]+                   # a hyphenated word of some sort
      (?:\\.[-\\w]+)?           # possibly qualified with '.Name'
      (?:\\#[-.\\w]*)?          # possibly having a #begin
      (?:\\#[-.\\w]*)?          # possibly having a #end
    )
    [:=]                        # followed by a ':' or an '='
  )

> What I would love is also a possible divider of => in addition to =
> and : , to indicate a direction. I use these to tie template pages
> with target pages in the markup.

If you want allow a divider of =>, then change the '[:=]' part
of the pattern to read '(?:=>?|:)'

Pm



More information about the pmwiki-users mailing list