I\'m trying to get the list of all digits preceding a hyphen in a given string (let\'s say in cell A1), using a Google Sheets regex formula :
=R
You may create your own custom function in the Script Editor:
function ExtractAllRegex(input, pattern,groupId) {
return Array.from(input.matchAll(new RegExp(pattern,'g')), x=>x[groupId]);
}
Or, if you need to return all matches in a single cell joined with some separator:
function ExtractAllRegex(input, pattern,groupId,separator) {
return Array.from(input.matchAll(new RegExp(pattern,'g')), x=>x[groupId]).join(separator);
}
Then, just call it like =ExtractAllRegex(A1, "\d-", 0, ", ").
Description:
input - current cell valuepattern - regex patterngroupId - Capturing group ID you want to extractseparator - text used to join the matched results.