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

Re: collectdata


  • Subject: Re: collectdata
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 14 Mar 2017 10:43:21 +1100

On 14 Mar 2017, at 2:24 am, Julien Battist <email@hidden> wrote:

Hi Shane, first of all this looks pretty stable and returns are colored nicely. Many thanks for this code which is still hard to read for me :)

It's obviously harder to read than plain AppleScript, but it does have the benefit of doing the job. And as far as I can see, there's still no viable alternative in the general case.
 
Coming back on regular expressions I would appreciate some feedback on the following.
In indesign I can grab data in a 'cell of a kolom' using a regular _expression_ where the first 5 characters are unique and the rest is grabbed being data in the same cell.
 
In a pdf this is separated with a space or a tab or even with nothing.
 
So what I want to grab is the following in bold: 
ABCD-123abc
Some text ABCD-abc234 some other text
ABCD-76y65yj90
ABCD-76yABC90 some text ABCD-code6547AA
----
 
ABCD- is fixed the rest can be random. What would be the right regular _expression_ for this?

There are plenty here more at home with regular expressions than me, but I think what you're after is:

set {theRegex, theError} to current application's NSRegularExpression's regularExpressionWithPattern:"ABCD-[ \\t]?\\S+" options:0 |error|:(reference)

That's ABCD- followed by nought or one spaces or tabs, followed by a string of non-space characters.

The thing you need to keep in mind is that it will also find "ABCD-123" in "XYZABCD-123". That might only be a theoretical concern given your data, but you could also specify that the pattern not be preceded by other than a space character, like this:

set {theRegex, theError} to current application's NSRegularExpression's regularExpressionWithPattern:"(?<!\\S)ABCD-[ \\t]?\\S+" options:0 |error|:(reference)

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
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

  • Follow-Ups:
    • Re: collectdata
      • From: Julien Battist <email@hidden>
References: 
 >collectdata (From: Julien Battist <email@hidden>)
 >Re: collectdata (From: Shane Stanley <email@hidden>)
 >Re: collectdata (From: Thomas Fischer <email@hidden>)
 >Re: collectdata (From: Julien Battist <email@hidden>)
 >Re: collectdata (From: Yvan KOENIG <email@hidden>)
 >Re: collectdata (From: Christopher Stone <email@hidden>)
 >Re: collectdata (From: Thomas Fischer <email@hidden>)
 >Re: collectdata (From: Julien Battist <email@hidden>)
 >Re: collectdata (From: Shane Stanley <email@hidden>)
 >Re: collectdata (From: Thomas Fischer <email@hidden>)
 >Re: collectdata (From: Shane Stanley <email@hidden>)
 >Re: collectdata (From: Shane Stanley <email@hidden>)
 >Re: collectdata (From: Julien Battist <email@hidden>)

  • Prev by Date: Re: Differences in output between AppleScript and Terminal
  • Next by Date: Re: collectdata
  • Previous by thread: Re: collectdata
  • Next by thread: Re: collectdata
  • Index(es):
    • Date
    • Thread