Re: Regular Expressions and Smile
Re: Regular Expressions and Smile
- Subject: Re: Regular Expressions and Smile
- From: "J.B. Stewart" <email@hidden>
- Date: Thu, 10 Jan 2002 20:35:27 -0500
On 1/10/02 at 5:39 PM, Daniel A. Shockley <email@hidden> wrote:
>
Any ideas?
>
>
Here's some sample code:
>
------------------
>
set myText to "John Smith
>
Jeff Matthewson
>
Robert Downing
>
JOHN Stephenson"
>
>
set newText to REReplace myText pattern "^John (.+)" with "\\1, John"
>
ignoreCase true
>
-------------
>
When you compile and run this, you get what you want. The script compiles to:
>
------
>
set myText to "John Smith
>
Jeff Matthewson
>
Robert Downing
>
JOHN Stephenson"
>
>
set newText to REReplace myText pattern "^John (.+)" with "\\1,
>
John" with ignoreCase
>
-------
>
and works, returning:
>
"Smith, John
>
Jeff Matthewson
>
Robert Downing
>
Stephenson, John"
>
>
If you leave out the ignoreCase, it won't change the JOHN Stephenson
>
line. Granted in this example you can add extra code to first
>
correctly capitalize the name, but that is just not possible for all
>
the places I've used BBEdit already.
>
>
However, now that the script has TWO 'with' commands, it will fail on
>
Syntax checking. This is bad, and I don't know of any way to keep
>
AppleScript from changing the form. Does anyone else?
>
>
Short of that, does anyone know a better or alternate way of doing
>
multiple fast greps in Mac OS 9 AppleScript? (I know I could use
>
other tools in Mac OS X, or even MacPerl)
You're gonna love this one, at least it works OMM using AS 1.7 OS 9.2.2 in
Script Debugger 3.0.1
John
set myText to "John Smith
Jeff Matthewson
Robert Downing
JOHN Stephenson"
-- following is all on one line
set newText to REReplace myText pattern "^John (.+)" with "\\1, John" ignoreCase
1 -- is "one" not "L"