Your script is very useful. I would suggest a small improvement to allow the use of capture groups. The reason is that JS probably has one of the most crippled regex flavors. To work around the lack of lookbehind or \K, you need capture groups. This could be important for instance in a file where you want to create a column using the nth group of digits.
With the current script this is a minor change. I'd suggest updating the column definitions to allow an optional "group" property.
Then we only need to replace line 65 with something like:
var capturegroup = (typeof config.group === 'undefined') ? 0 : config.group;
scriptColData.value = result[capturegroup];
Here is a quick example of definitions for a hypothetical file convention that would include a phone number and name:
//Name of column, Title.
//regexp to extract value
// group to be returned (optional if whole match, i.e. group 0)
// group: 0
re: /^\d+\D+(\d+[- ]\d+)/,
re: /^\d+\D+\d+[- ]\d+\s*(\S+)/,
(Attaching these incorporated changes for the convenience of anyone interested. Didn't know what to do with the version number and naming convention, sorry if it is wrong.)
Here we're running three match attempts when one pattern would be enough to fan the data into three groups, and that's a bit of a shame. It would be better if we could use a single regex for all three columns, using various capture groups as results. I haven't studied the scripting interface so have no idea if processing multiple columns at once is possible.
CustomtextColumn with Groups.js.txt (2.38 KB)