Regular expressions
Terry Vogelaar
tvogelaar at de-mare.nl
Tue Jul 2 07:19:27 EDT 2013
GREP saved my bacon in several occasions. And the regular expressions in LC are somewhat similar to GREP, but not quite.
In GREP I can do this:
stringToChange: <body><span>Block of text</span></body>
matchExpression: <span>[^<]+</span>
replacementString: <div>?</div>
result: <body><div><span>Block of text</span></div></body>
The question-mark fills in everything that matches the matchExpression. Very useful when you want to put something around the found instances.
Or you can even take it a step further by using ( and ) in combination with \1, \2 etc.:
stringToChange: <body><span class="MakeMeVisible">Block of text</span></body>
matchExpression: <span class="([^"]+)">([^<]+)</span>
replacementString: <span>\1: \2</span>
result: <body><span>MakeMeVisible: Block of text</span></body>
The \1 fills in what it found inside the first pair of parentheses; the \2 the second pair. This way you can do really powerful replacements, if you know what you are doing.
So I wonder how I do this in LC. I know I need to use Perlre and not GREP. So how do I do this in Perlre?
Terry
More information about the use-livecode
mailing list