Re: Pseudo-regexp
Re: Pseudo-regexp
- Subject: Re: Pseudo-regexp
- From: Adam Wuellner <email@hidden>
- Date: Mon, 28 Feb 2005 14:30:25 -0600
On Mon, 28 Feb 2005 14:52:20 -0500, Elliotte Harold
<email@hidden> wrote:
> <snip>
> The final step is to parse the From: and Date: headers out of the raw
> message text. This is pretty straight-forward string manipulation, and I
> I'm hoping it's obvious to someone. In other words, I have this:
>
> ...
> 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?
AppleScript's text item delimiters could probably be called in to work here:
<script>
set rawmessage to "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
"
set AppleScript's text item delimiters to {"Date: "}
set message_date to paragraph 1 of text item 2 of rawmessage
-- "Mon, 28 Feb 2005 10:43:14 -0800 (PST)"
set AppleScript's text item delimiters to {"From: "}
set message_from to paragraph 1 of text item 2 of rawmessage
-- "rlk groups <email@hidden>"
</script>
> If there's not, is there an easy way to call out to Perl or some such to
> do this work?
You can do that, too, if your pattern-matching requirements become
more complex. See 'do shell script' from Standard Additions'
dictionary. Basically,
do shell script "any valid command line syntax"
will return the standard output of "any valid command line syntax".
> <snip>
_______________________________________________
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
References: | |
| >Pseudo-regexp (From: Elliotte Harold <email@hidden>) |