• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Easier way to check for numbered string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Easier way to check for numbered string


  • Subject: Re: Easier way to check for numbered string
  • From: has <email@hidden>
  • Date: Fri, 27 Apr 2007 19:58:58 +0100

Chris Tangora wrote:

I have a script that goes through and pulls specific characters out of a filename and checks to see if they are all numbers. While it works now, I was hoping somebody knew of a more efficient way of doing this. What I would prefer to figure out is a way to do it with a series of if then else if's, but I haven't figured that part out yet. Any help is appreciated.

You could use regular expressions to check for the desired patterns. e.g. Using TextCommands <http://osaxen.com/files/ textcommands1.1.2.html>:


set file_names to {"01ABCDEF-Z-1234.pdf", "1NJ0100A1234.pdf", "#PP1NJ0100A1234.pdf"}

repeat with file_name in file_names
tell application "TextCommands"
set is_match to check file_name contains "^\\d{2}|^.{3}\\d{4}|^.{7} \\d{3}"
end tell
log is_match --> true, true, true
end repeat


The regular expression string is translated from the code in your second post:

^ -- match from the start of a line
. -- match any character
\d -- match any digit from 0 to 9
{n} -- match n occurrences of the previous pattern (e.g. \d{2} = match two digits)
| -- 'or'


HTH

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html

_______________________________________________
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/archives/applescript-users

This email sent to email@hidden
  • Prev by Date: Re: Easier way to check for numbered string
  • Next by Date: Excel problems switching between documents
  • Previous by thread: Re: Easier way to check for numbered string
  • Next by thread: Re: Easier way to check for numbered string
  • Index(es):
    • Date
    • Thread