Re: Capturing parts of text string
Re: Capturing parts of text string
- Subject: Re: Capturing parts of text string
- From: has <email@hidden>
- Date: Mon, 4 Jul 2005 09:35:17 +0100
Patrick Collins wrote:
>Just curious if I have a string:
>
>set x to "Las Vegas, Nevada 89102"
>
>how is the best way to extract the city, state, and zip into their own
>strings?
Regular expressions are absolutely ideal for this sort of thing. Example (uses TextCommands <http://freespace.virgin.net/hamish.sanderson/index.html#textcommands>):
-------
set txt to "Las Vegas, Nevada 89102
Northbrook, IL 60062
Las Cruces, New Mexico 85123-1234"
tell application "TextCommands"
set txt to change linebreaks txt to Unix format
search txt for "^(.*?), (.*?) ([-0-9]+)$" with regex and individual line matching
end tell
--> {{"Las Vegas", "Nevada", "89102"}, {"Northbrook", "IL", "60062"}, {"Las Cruces", "New Mexico", "85123-1234"}}
-------
You might need to finesse the search pattern a bit depending exactly on how your input data is presented, but this shouldn't be hard. If you've not used regular expressions before, there's plenty of tutorials available online and in book form.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
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