[pmwiki-users] Re: Modified (:markup:)

Joachim Durchholz jo at durchholz.org
Mon Mar 21 01:44:40 CST 2005


Patrick R. Michaud wrote:
> On Sun, Mar 20, 2005 at 04:36:24PM -0500, Neil Herber wrote:
> 
>> I would suggest that we agree on the equal-sign-incrementing and
>> move on to other matters.
> 
> I agree, but my implementation of [== ... ==]  currently breaks in 
> the face of text containing multiple [==]'s, so I have to either come
> up with a much better pattern or go back to the drawing board.

Would a backreference work?

   \[(=*)[^=](.*?)\1\]

The (=*) captures the string of =s after the opening [ and stores them 
in the $1 variable, the [^= makes sure that a non-= is between the 
brackest-and-equals-signs delimiters (else we'd match stuff like [==] 
and we don't want that - might be a useful markup for other purposes), 
the (.*?) eats up the least number of characters before the final 
pattern (so we don't take [=...=]...[=...=] as a single pattern), the \1 
requests the same string as was captured in $1.
To ensure that the replacement pattern gives the right output, we'd need 
to add a set of parentheses; a micro-optimization also eliminates an 
unneeded $3 capture:

   \[(=*)([^=](?.*?))\1\]
         ^     ^    ^

(Apologies if the above regexes contain errors - they are untested.)

Regards,
Jo



More information about the pmwiki-users mailing list