Re: Capturing parts of text string [Re: Applescript-users Digest, Vol 2, Issue 443]
Re: Capturing parts of text string [Re: Applescript-users Digest, Vol 2, Issue 443]
- Subject: Re: Capturing parts of text string [Re: Applescript-users Digest, Vol 2, Issue 443]
- From: kai <email@hidden>
- Date: Wed, 6 Jul 2005 01:39:01 +0100
On Tuesday, July 5, 2005, at 07:14 pm, has wrote:
Bear in mind that RE features and syntax can vary a bit from
implementation to implementation, so not everything you read about
System X will be exactly the same for System Y (e.g. POSIX-style REs
would use '[[:space:]]' instead of '\s'), but the basic principles and
syntax are generally the same - and more than enough to blow away any
ad-hoc vanilla AS alternative.
I share your enthusiasm for regular expressions, has - especially when
there's some heavy lifting to be done. I've also found TextCommands a
most valuable addition to my toolbox - thanks very much for that.
(/commercial)
That said, I can't help thinking it a pity if a vanilla approach
couldn't cope with a relatively simple text cleaning exercise. Perhaps
something like:
-------------------------
on locationAsCleanList(l)
set d to text item delimiters
set text item delimiters to item 1 of (l's word -2)
set z to count "0123456789"'s text items
set text item delimiters to ","
tell l to set c to count text item 1's words
set text item delimiters to space
tell l's words 1 thru -(z + 1) to set r to (beginning & ({""} &
rest))'s ¬
{text from beginning to word c, text from word (c + 1) to end}
set text item delimiters to "-"
tell l's words -z thru -1 to set r's end to beginning & ({""} & rest)
set text item delimiters to d
r
end locationAsCleanList
set txt to " Las Vegas , Nevada 89102
Northbrook,IL 60062
Las Cruces ,New Mexico 85123-1234 "
set l to txt's paragraphs
repeat with n from 1 to count l
set l's item n to locationAsCleanList(l's item n)
end repeat
l
--> {{"Las Vegas", "Nevada", "89102"}, {"Northbrook", "IL", "60062"},
{"Las Cruces", "New Mexico", "85123-1234"}}
-------------------------
Of course, I readily defer in the brevity stakes... :)
---
kai
_______________________________________________
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