regex question

Martin Baxter mb.ur at harbourhost.co.uk
Thu Dec 1 17:06:31 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, try..

matchChunk(tRawText, "(?s)<B>(.+?)</B>", tPos, tEnd)

does what you want here.

Martin Baxter



More information about the use-livecode mailing list