I tried the same regular expression both in python (3.6, jupyter notebook) and Google app script, but it seems like \"non-capturing group\" is not working in the app script
First of all, you need to use \\
before .
in the GAS regex declaration, as the literal backslash forms a regex escape sequence.
Now, it seems that GAS non-capturing group implementation is buggy.
If you run your regex in GAS and print the Match
object, you will see
[18-01-26 08:49:07:198 CET] [<a class=""email"" href=""mailto:SOisAwesome@hello.edu"">,
a class=""email"" href=""mailto:SOisAwesome@hello.edu, "">]
That means, the non-capturing group got "merged" with the first capturing group skipping the first char.
Here are some more experiments:
Logger.log(new RegExp("(?:;\\w+):(\\d+)").exec(";er:34")); // = null, expected [;er:34, 34]
Logger.log(new RegExp("(?:e\\w+):(\\d+)").exec(";er:34")); // = null, expected [er:34, 34]
Logger.log(new RegExp("(?:\\w+):(\\d+)").exec(";er:34")); // = [er:34, 34], as expected
To fix the issue, you may remove the non-capturing parentheses, as \d
= (?:\d)
.