[thelist] ASP/RegExp
Wade Armstrong
wade_lists at runstrong.com
Thu Oct 3 13:05:01 CDT 2002
on 10/3/02 10:57 AM, Chris Marsh at chris at webbtech.co.uk wrote:
>> sPattern = "<<wttoc>>([\n]|.)*<</wttoc>>"
>
> That's great, thanks! My next problem however, is that this matches the
> following entire string:
>
> <<wttoc>>Hello There<</wttoc>>
> This is cool.
> <<wttoc>>Hello There<</wttoc>>
> This is cool.
> <<wttoc>>Hello There<</wttoc>>
>
> Whereas I want it match:
>
> <<wttoc>>Hello There<</wttoc>>
The problem is that the RegExp engine is being "greedy" - it's matching the
longest possible string between <<wttoc>> and <</wttoc>>. You want to set it
to be non-greedy, by using the pattern:
sPattern = "<<wttoc>>([\n]|.)*?<</wttoc>>"
^
See that question mark there? that's the character you're looking for. With
that, it should match the shortest possible string between <<wttoc>> and
<</wttoc>>.
Wade
More information about the thelist
mailing list