regex question

Alex Tweedly alex at tweedly.net
Thu Dec 1 17:45:44 EST 2005


Mark Wieder wrote:

>All-
>
>Is there a way to tell matchChunk() not to be greedy?
>
>I've got a regular expression stumper here. I'm using regex with the
>matchChunk() function and I've BZed a problem with it. Now I'm looking
>for a workaround that still manages to use matchChunk().
>
>MatchChunk() is apparently implementing regex's "greedy" mode, so a
>call to matchChunk() returns everything between the first <B> tag and
>the *last* </B> tag. So...
>
>put "<B>hello, bucko</B> this is a <B>test</B>"
>matchChunk(tRawText, "(?s)<B>(.+)</B>", tPos, tEnd)
>
>returns "hello, bucko</B> this is a <B>test"
>
>What I'd like to return is just "hello, bucko". Is there some regex
>incantation that will do this for me? I can't seem to come up with it.
>
>  
>
Mark,

see the "Strip HTML" demo stack from the Text Munging conference stack :-)

It uses the regex      (<(.|\n)+?>)   
 the "?" makes it lazy instead of greedy.

-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.10/189 - Release Date: 30/11/2005




More information about the use-livecode mailing list