Does omitting non-capturing groups ?: have a negative effect on RegExp.prototype.test()?

47 Views Asked by At

I am currently testing a string to be in a specific mail format.

/^[A-Za-z0-9](([A-Za-z0-9]|\.(?!\.))*[A-Za-z0-9]+)?@[A-Za-z0-9]+\.[A-Za-z]{2,}$/.test(email)

Now I have some parenthesis which could be marked as non-capturing groups like this:

/^[A-Za-z0-9](?:(?:[A-Za-z0-9]|\.(?!\.))*[A-Za-z0-9]+)?@[A-Za-z0-9]+\.[A-Za-z]{2,}$/.test(email)

But I don't see any difference between the results. Tests only checks, so it should be irrelevant, shouldn't it?

1

There are 1 best solutions below

0
On BEST ANSWER

Switching between capturing and noncapturing groups in test is relevant only if you use backreferences (\1 \2). As you don't, the change has no effect.