Re: Parsing text from a string
Re: Parsing text from a string
- Subject: Re: Parsing text from a string
- From: Emmanuel <email@hidden>
- Date: Thu, 17 Mar 2005 00:06:49 +0100
At 10:18 AM -0800 3/16/05, Todd Geist wrote:
Hello again.
I am just full of questions today :>)
If I have the string "Have a [Nice] [Day]"
I want what is in the first set of brackets "Nice". The brackets will
always be somewhere in the string and I want what is in side of them.
If you intend to do more text processing in the future, maybe you may
consider installing the Satimage osax (it's free and unobtrusive) and
use Regular Expressions through its verbs "find text" and "change".
You can use Regular expressions through the shell, too, but the
syntax is more intuitive with the Satimage osax.
The problem with regexp is that they are ugly.
[^a] means "whatever except a", so "whatever except [" is [^[], which
is already rather ugly. You want that the regular expression read all
(that's *) non-[ characters from the beginning (that's ^), which
reads ^[^[]*. And then you want the opening bracket, then non-], then
the closing bracket. Since bracket is a special character, you've got
to escape it! This makes the reg exp still more ugly: ^[^[]*\[[^]]*.
There is no need specifying that the non-] has to end with ], since
that implementation of the regular expressions always goes as far as
it can. Finally you have to say what you want in that pattern: you
want the thing between the brackets, so enclose it between
parentheses:
^[^[]*\[([^]]*)
and tell to the command that you want the first "group" (code name: \1):
find text "^[^[]*\\[([^]]*)" in "Have a [Nice] [Day]" with regexp and
string result using "\\1"
-- "Nice"
(you note that for still more ugliness you've got to double the
backslashes to escape them from AppleScript.)
Emmanuel
from Satimage-software, the authors of Satimage.osax.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden