• 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: NSRegular expression question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSRegular expression question


  • Subject: Re: NSRegular expression question
  • From: Jim Weisbin <email@hidden>
  • Date: Sat, 2 Sep 2017 11:12:05 -0400

This works perfectly, thanks all. I have set the AppleScript to version 2.3, so
I think it will run on Mavericks.

use AppleScript version "2.3"
use framework "Foundation"
use scripting additions

set theFileName to "Human_012345_something_123456.mp3"
set pathString to current application's NSString's stringWithString:theFileName
set theExtension to pathString's pathExtension()
set thePathNoExt to pathString's stringByDeletingPathExtension()
set theText to current application's NSString's stringWithString:thePathNoExt
set matchRange to theText's rangeOfString:"(\\d){6}$" options:(current
application's NSRegularExpressionSearch)
if matchRange's |length| > 0 then
        set theWord to (theText's substringWithRange:matchRange) as text
        -- do the DB look up here

else -- not found
        set theWord to ""
end if

One other question - the number is always padded to six digits in the filename.
But in the database, the leading zeroes, if any, don’t exist. To get rid of the
leading zeroes in order to do the look up, I’m casting the string to an
integer, which works. It’s guaranteed to be a number based on the regex above,
but is there any down side to doing it that way?


Jim Weisbin | C.T.O. | Human | Post Human | 27 West 20th Street | Suite 801 |
New York, NY | 10011 |  (212) 352-0211 |  (917) 375-2272 | 2046 Broadway |
Santa Monica, CA | 90404 |  (310) 264-0211 telephone | www.humanworldwide.com
<http://www.humanworldwide.com/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSRegular expression question
      • From: Shane Stanley <email@hidden>
References: 
 >Re: NSRegular expression question (From: Jim Weisbin <email@hidden>)
 >Re: NSRegular expression question (From: Jim Weisbin <email@hidden>)

  • Prev by Date: Re: NSRegular expression question
  • Next by Date: Re: NSRegular expression question
  • Previous by thread: Re: NSRegular expression question
  • Next by thread: Re: NSRegular expression question
  • Index(es):
    • Date
    • Thread