• 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 09:42:58 -0400

Thanks!

 Shane Stanley <email@hidden> wrote:
>
> There's a special method for getting the first match, which is effectively
> what you're after: firstMatchInString:options:range:. In fact, there's
> another for getting the range directly:
>
> use AppleScript version "2.4" -- Yosemite (10.10) or later
> use framework "Foundation"
> use scripting additions
>
> set theText to current application's NSString's
> stringWithString:"Human_012345_something_123456"
> set myRegex to current application's NSRegularExpression's
> regularExpressionWithPattern:"(\\d){6}$" options:0 |error|:(missing value)
> set matchRange to myRegex's rangeOfFirstMatchInString:theText options:0
> range:{0, theText's |length|()}
> set theWord to (theText's substringWithRange:matchRange) as text
> display dialog theWord as text
>
> Or even simpler:
>
> use AppleScript version "2.4" -- Yosemite (10.10) or later
> use framework "Foundation"
> use scripting additions
>
> set theText to current application's NSString's
> stringWithString:"Human_012345_something_123456"
> set matchRange to theText's rangeOfString:"(\\d){6}$" options:(current
> application's NSRegularExpressionSearch)
> set theWord to (theText's substringWithRange:matchRange) as text
> display dialog theWord as text
>

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: 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