Re: Regular Expressions and Smile
Re: Regular Expressions and Smile
- Subject: Re: Regular Expressions and Smile
- From: has <email@hidden>
- Date: Fri, 11 Jan 2002 11:33:42 +0000
Daniel A. Shockley wrote:
>
I'm trying to do regular expressions and running into some annoying
>
problems. Perhaps I'm missing some knowledge of Regular Expressions,
>
but I've run into a serious problem with RegEx by Lenoard Rosenthal.
[snip]
>
Does anyone else notice a major problem here?
>
>
'with' is a _reserved_ word in AppleScript. Interestingly enough, it
>
lets you use with as a keyword, which is all fine and good until you
>
want to include the option 'ignoreCase true.' When you compile that,
>
the compiler automatically "helps" you out by changing that into
>
'with ignoreCase' which works when you run it.
I don't know if this problem is one with the osax or with AS in general.
The 'with/without' keyword seems a great idea... on paper (it's discussed
under the labelled parameters section of the handlers chapter in ASLG.).
But it has a habit of sending things off the rails at times. I'm sure it's
given me trouble in the past as well.
To work around this problem, you can use:
REReplace "blah blah" with "X" pattern "B" ignoreCase 1
Which is maybe a little bit of a hack, but should solve your problem for you.
Sometimes I wish AS used regular function call syntax for osaxen and
applications as well, eg:
REReplace(inString:"blah blah", with:"X", pattern:".A.", ignoreCase:true)
It's easy enough to see why not: the above is still pretty readable, but
not quite as 'plain English'. Just a pity that some robustness was lost as
a result, as keyword clashes and broken compiles aren't much fun either. :(
>
Satimage's RegEx functions
>
also don't work, as you can't use parentheses groups to get parts of
>
matches into the replacement string.
Back references? It's just the same as for RegEx Commands: use an escaped
digit between 1 and 9. For example:
change "(.)(.)" in "blah blah" into "\\2\\1" regexpflag {"EXTENDED",
"NEWLINE", "ICASE"} with regexp
(Just remember that you have to 'escape the escape': the documentation for
regex in Smile maybe doesn't make this obvious as it's referring more to
their use in Smile's find-and-replace dialog.)
The Satimage regex lacks a couple of the niceties found in RegEx Commands
(e.g. "&#@"), but I kinda get the impression that no two implementations of
regex are ever quite the same anyway. You gotta just pays your money and
takes your choice.
HTH
has