regex question
Jim Ault
JimAultWins at yahoo.com
Fri Dec 2 03:40:46 EST 2005
On 12/1/05 11:51 PM, "Mark Wieder" <mwieder at ahsoftware.net> wrote:
> Martin-
> Thursday, December 1, 2005, 2:06:31 PM, you wrote:
>> matchChunk(tRawText, "(?s)<B>(.+?)</B>", tPos, tEnd)
>
> Thanks to all for the great replies. The .+? syntax does indeed solve
> my problem, as does the uppercase U. I puzzled over this for a while,
> trying to figure out why the ? made a difference after I already
> specified the pattern I wanted, and then suddenly the light bulb went
> off and I got it. It's specifying *at most* one occurence of the
> string. Brilliant. Regex rules.
Correct, Mark. If you happen to use BBEdit, their docs cover the use of the
'?' to mean ungreedy for that *location* in the RegEx expression. Beware
that the '?' used this way can give unexpected results. It is less
consistent than using 'U' and applying it to the whole expression
As always, test before trusting.
Try this "or" structure in BBEdit or a repeat loop with matchChunk:
--example-- 4 expressions, applied to a following text block
(?i)KillerApp(ver001.*exe?|ver002.*exe?|ver003?) -->whole line+ parts+more
(?i)KillerApp(ver001.*exe|ver002.*exe|ver003) -->whole line+parts
(?si)KillerApp(ver001.*exe|ver002.*exe|ver003) -->all characters
(?Usi)KillerApp(ver001.*exe|ver002.*exe|ver003) -->each part
--start text
KillerAppVer001a.exe, KillerAppVer001b.exejunk
KillerAppVer002a.exe, KillerAppVer002b.exe/ extra stuff
KillerAppVer003c.exe, KillerAppVer003d.exe
KillerAppVer004d.exe
KillerAppVer005d.exe
--end text
Jim Ault
Las Vegas
More information about the use-livecode
mailing list