Re: Pseudo-regexp
Re: Pseudo-regexp
- Subject: Re: Pseudo-regexp
- From: Emmanuel <email@hidden>
- Date: Tue, 1 Mar 2005 10:29:15 +0100
At 2:52 PM -0500 2/28/05, Elliotte Harold wrote:
Message-ID: <email@hidden>
Date: Mon, 28 Feb 2005 10:43:14 -0800 (PST)
From: rlk groups <email@hidden>
To: email@hidden
MIME-Version: 1.0
...
I have this complete message stored in a string variable called rawmessage.
I need to extract "rlk groups <email@hidden>" and "Mon, 28
Feb 2005 10:43:14 -0800 (PST)" and store them in new variables.
Regular expressions would make this task easy, but as far as I know
(I could be wrong about this) AppleScript doesn't have these without
3rd party libraries. Is there any straightforward string operations
that could pull this off?
If there's not, is there an easy way to call out to Perl or some
such to do this work?
And if that's not the case, what's the best cheap regex library for
AppleScript? SatImage?
For what it's worth this does not run unattended. I can afford a
quick and dirty solution that may fail on some corner cases and have
to be manually corrected.
All suggestions are appreciated.
Other than Satimage.osax (that we provide for free), you call the shell's grep.
When you work in AppleScript, you may prefer using the Satimage.osax
because it is AppleScript-savvy: it can "find text" and "change" in
files, it can work on lists of strings rather than strings etc.
Performance-wise, small tasks with grep imply a non-negligible
overhead, since you really launch a process.
We document the Regular expressions with the Satimage osax at:
<http://www.satimage.fr/software/en/reg_exp.html>
Your request would give:
set thefrom to find text "^From: (.+)" in themail using "\\1" with
regexp and string result
set theDate to find text "^Date: (.+)" in themail using "\\1" with
regexp and string result
"themail" may be the contents of the mail (a string) as well as a
reference to a file.
And since you're in AppleScript you can even get directly an AppleScript date:
set theASDate to date (find text "^Date: (.+)" in themail using "\\1"
with regexp and string result)
Finally, the AppleScript environment is certainly to be recommended
rather than the shell's grep if you do have Unicode to handle.
Emmanuel
_______________________________________________
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