[Pmwiki-users] free links question

Jonathan Scott Duff duff
Wed Mar 3 10:54:28 CST 2004


On Wed, Mar 03, 2004 at 08:42:52AM -0800, Steven Leite wrote:
> Yes.  And on that note, can anybody suggest a good tutorial place for
> RegExp?  

If you have perl installed, these are useful commands to use (they
work on MS Windows too):

perldoc perlretut
perldoc perlre

(oh, and if you're on debian you might need to do "apt-get perl-doc"
(or whatever the command is) because debian doesn't give you the
documentation for perl unless you've asked for it)

> I want to learn for the sole purpose of understanding the
> $GroupFreeLinkPattern an no other purpose.  

I'm not sure if PCRE (or php's binding to PCRE) supports the same notion
of "extended" patterns that perl does, but if so you could encourage Pm
to use it and comment his regular expressions.  It would allow the REs
to look something like this:

$GroupFreeLinkPattern= "
  {{					# freelinks start with {{
    (?>					# "cut" operator
      (?:				# non-capturing group
       ($GroupNamePattern)		# PmWiki GroupName (captured)
       ([.\\/])				# separator (captured)
      )?				# preceding group is optional
      (					# start of freelink text (captured)
        [[:alpha:]]			# must start with an alpha
        [[:alnum:]]*			# can contain alphanumerics after
        (?:
          (?:
            [\\s_]*			# zero or more spaces or underscores
            |-				# or exactly one dash
          )
          [[:alnum:]]+			# and more alphanumerics
        )*
      )					# end of freelink text
      (?:
        \\|((?:(?:[\\s_]*|-)[[:alnum:]])*)	# cut text
      )?					# optional 
    )
  }}					# end of freelink
  ((?:-?[[:alnum:]]+)*)			# replacement text (captured)
";

Okay, I balked at describing the cut operator and much of the pattern
but there's only so much time in my day :-)

Basically the cut operator prevents backtracking beyond that point. If
the pattern inside of the "cut" doesn't match, it causes the whole
pattern to fail rather than backtracking to try other alternatives.
Understanding the rest of the pattern is left as an exercise for the
reader  :-)

-Scott
-- 
Jonathan Scott Duff
duff at pobox.com



More information about the pmwiki-users mailing list