[Mediawiki-l] REGEXP for wiki tables

Benct Philip Jonsson bpj at melroch.se
Thu Aug 6 20:39:21 UTC 2009


Christensen, Courtney skrev:
> Benct Philip Jonsson wrote:
>> On 2009-08-05 Matthias Korn wrote:
>>> I have now settled with "\{[^\}]+\}" which is far from 
>>> perfect, because
>>> it also matches (partially) on templates. But that's ok.
>>>
>> s/\{\|.+?\|\}//gs would do a lot better, since wikitables
>> start in "{|" and end in "|}" and would not touch
>> templates.
>>
>> /BP
> 
> But that would sometimes grab more than just one table.
> -Courtney

Not with the lazy quantifier +?: /.+?\|\}/ means "as few chars
as possible up to an "|}"; thus the match will stop at the
first "|}", and thus at most one table can participate in
each match. Contrast /.+\|\}/ without the ? which will
match everything up to the last "|}" in the string/file.
(Ignoring for the sake of uncluttering the /s modifier
necessary to have .+? or .+ match spans including newlines!)

/BP



More information about the MediaWiki-l mailing list