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 22:34:59 +0100
Robert Poland wrote:
>Not to "beat a dead horse"...
>(* Strip leading spaces, double spaces and converts "space," to ","
>*)
Dealing with uncertain whitespace padding is absolutely trivial when using regular expressions:
-------
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 "^\\s*(.*?)\\s*,\\s*(.*?)\\s+([-0-9]+)\\s*$" with regex and individual line matching
end tell
--> {{"Las Vegas", "Nevada", "89102"}, {"Northbrook", "IL", "60062"}, {"Las Cruces", "New Mexico", "85123-1234"}}
-------
Like I say, regular expressions are a tremendously powerful and invaluable tool, and an absolute must-have for text processing work. It's unfortunate that Apple don't include a regex osax as standard, but there's no shortage of good third-party alternatives. They take a little bit of learning but it's totally worth it, and there's loads of printed and online resources to help; not just tutorials but scads of ready-to-use patterns for all sorts of common tasks too (e.g. finding hyperlinks and email addresses, tidying US phone numbers, etc, etc etc). I can't recommend them enough.
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