Re: Optimizing Character Matching
Re: Optimizing Character Matching
- Subject: Re: Optimizing Character Matching
- From: Tim Mansour <email@hidden>
- Date: Sun, 5 Nov 2006 18:02:30 +1100
On 05/11/2006, at 12:39 pm, Rick Gordon wrote:
Does this string contain any character in a list of known bad
characters?
OR
Does this string contain any character besides [A-Za-z0-9], and
does it begin with a digit?
Both of which are easily accomplished using regular expressions. With
Satimage.osax installed:
find text "[ _<>()*~-]" in stringToSearch regexp true
will return a result if one of the characters between the brackets*
is in stringToSearch. And:
find text "^[0-9][A-Za-z0-9]+$" in stringToSearch regexp true
will return a result only if stringToSearch is alphanumeric, starting
with a digit.
In both cases, the "find text" command throws an error if no match is
found. So if you're only interested in a boolean result you could
trap for an error in each case. For instance:
try
find text "[ _<>()*~-]" in stringToSearch regexp true
set badCharsFound to true
on error
set badCharsFound to false
end try
*note the hyphen should be last
--
Tim Mansour <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden