If you desperately need a different RegEx backend other than RE2, you can use an App Script to create a custom function that uses JS to evaluate the RegEx.
- Click Tools > Script Editor.
- In the editor add your custom JS RegEx function. You can use the example below.
- Give it a name
JS_REGEXEXTRACT
is a good option.
- Click save button in the toolbar.
- Go back to the browser tab with your Sheet in it, and replace
REGEXEXTRACT
with JS_REGEXEXTRACT
.
You now have a working JS base RegEx option. It will not be as fast as the RE2 implementation, so be careful on large datasets with complex expressions.
/**
* Extracts matching substrings according to a regular expression using JS not RE2.
*
* @param {"abcdefg"} text The input text.
* @param {"c.*f"} regular_expression The first part of `text` that matches this expression will be returned.
* @return Extracts matching substrings according to a regular expression.
* @customfunction
*/
function JS_REGEXEXTRACT(text, regular_expression) {
if (text.length < 1) {
return null;
}
matches = text.match(new RegExp(regular_expression))
if (matches && matches.length >= 1) {
return matches[1];
}
return matches;
}