[wiki-standards] Re: Better Creole Tests?
Michael B Allen
ioplex at gmail.com
Sat Jul 26 20:02:44 CEST 2008
On Sat, Jul 26, 2008 at 12:40 PM, Radomir Dopieralski
<wikistandards at sheep.art.pl> wrote:
> Sat, Jul 26, 2008 at 12:17:38PM -0400:
>> On Sat, Jul 26, 2008 at 3:07 AM, Radomir Dopieralski
>> <wikistandards at sheep.art.pl> wrote:
>> > Sat, Jul 26, 2008 at 12:09:32AM -0400:
>> >> On Fri, Jul 25, 2008 at 5:10 PM, Michael B Allen <ioplex at gmail.com> wrote:
>> >
>> >> Can anyone suggest a regex to match the last three }}} in a sequence
>> >> of more than three?
>> >
>> > I use something like this (Python):
>> >
>> > ur"[{][{][{](?P<code_text>([^}]|[^}][}]|[^}][}][}])*[}]*)[}][}][}]"
>>
>> This isn't going to help me because I don't match the entire nowiki
>> block with one regex. I use regex only to tokenize the stream such
>> that I'm getting tokens '{{{', 'some text', '}}}', '\n', '===', ....
>>
>> I need a regex that just matches the last occurrence of three closing
>> curly braces in a sequence of more than three.
>
> Um... that's pretty straightforward no? Exactly how you describe:
>
> }}}(?!})
Indeed that would be perfect.
Unfortunately because my tokenizer uses a single regex with an OR
condition for each token, the image closing token '}}' matches before
the look-ahead expression. So it seems a look-ahead expression doesn't
follow the precedence expected.
Meaning an expression and input like:
$expr = '/(}}}(?!}))|(}})/';
$input = 'foo}}}}bar';
will always match the image closing markup '}}' before the look-ahead
expression.
> I'm not sure that using tokens in the way you describe is a good
> idea in the specific case of wiki markup -- it surely makes a lot
> of things more complicated.
It's not complicated. When I get a '}}}}' token, I output one '}',
unget '}}}' and continue at the top of the loop. It's 4 lines of code
and is completely isolated.
Of course it would be better if it could be handled with only regex
but these sort of clauses are common for a tokenizer + loop model.
Mike
--
Michael B Allen
PHP Active Directory SPNEGO SSO
http://www.ioplex.com/
More information about the wiki-standards
mailing list