The test()
method executes a search for a match between a regular expression and a specified string. Returns true
or false
.
JavaScript RegExp
objects are stateful when they have the global
or sticky
flags set (e.g., /foo/g
or /foo/y
). They store a lastIndex
from the previous match. Using this internally, test()
can be used to iterate over multiple matches in a string of text (with capture groups).