JS: 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 Flag〕
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
- JS: RegExp Tutorial
- JS: Regex Functions
- JS: RegExp Syntax
- JS: RegExp Flag
- JS: Regex Replace String Dollar Sign
- JS: Regex Replace Function Args
- JS: RegExp Object
- JS: RegExp Constructor
- JS: RegExp.prototype
- JS: String.prototype.search
- JS: String.prototype.match
- JS: String.prototype.matchAll
- JS: String.prototype.replace
- JS: String.prototype.replaceAll
- JS: RegExp.prototype.test
- JS: RegExp.prototype.exec