Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optimizing Character Matching




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:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden
References: 
 >Optimizing Character Matching (From: Rick Gordon <email@hidden>)
 >Re: Optimizing Character Matching (From: Tim Mansour <email@hidden>)
 >Re: Optimizing Character Matching (From: Rick Gordon <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.