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)