Julien et al,
This probably doesn't fit in with your overall requirements, but just as an example of how easy it is to use the _javascript_ RegEx engine with _javascript_ for Automation (JXA), here's a solution for just the RegEx part.
This returns a _javascript_ array (aka list) with each RegEx Capture Group.
Also, I have found
Regex101.com to be a great resource in developing and testing RegEx.
BTW, in theory, according to Apple, you should be able to do in JXA what you have done in AppleScript.
'use strict';
(function run()
{ // this will auto-run when script is executed
/*
REQUIRES:
• macOS 10.11+
*/
var sourceStr =
`
ABCD-123abc
Some text ABCD-abc234 some other text
ABCD-76y65yj90
ABCD-76yABC90 some text ABCD-code6547AA
`
var regEx =
/(ABCD\-[^\s]+)/g;
var captureList = [];
var matchResults;
while (matchResults = regEx.exec(sourceStr)) {
captureList.push(matchResults[1]);
}
return captureList
}
// END of function run()
)();
//--- RESULTS ---
/*
["ABCD-123abc", "ABCD-abc234", "ABCD-76y65yj90", "ABCD-76yABC90", "ABCD-code6547AA"]
*/
Jim Underwood
aka JMichaelTX
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?
Many thanks for any feedback,
Julien