Use the correct RegExp method

In general:

  • Use .test if you want a fast boolean check.
  • Use .match to retrieve all matches when using the g flag.

It is possible to gain extra perfomance using String method to match RegExp instead of RegExp to match String. It depends on your use case and of your JavaScript engine. Check test#1, test#2 and test#3 benchmarks.