JavaScript: RegExp.prototype.test
regex.test(string)
-
Return
true
if regex match part or whole of string, elsefalse
. If there is a global flagg
, repeated call will start fromRegExp.prototype.lastIndex
. [see RegExp Flags]
console.log(/4/.test("345") === true); console.log(/4/.test("999") === false);
Repeated call with global flag.
const gx = /4/g; console.log(gx.lastIndex === 0); console.log(gx.test("345678") === true); console.log(gx.lastIndex === 2); console.log(gx.test("345678") === false); console.log(gx.lastIndex === 0);
JavaScript Regular Expression
- RegExp Tutorial
- RegExp Functions
- RegExp Syntax
- RegExp Flags
- Replacement String Dollar Sign Sequence
- Replacement Function Arguments