JS: RegExp.prototype.test
regexObj.test(string)
-
- Return
true
if regexObj match part or whole of string, elsefalse
. - If there is a global flag
g
, repeated call 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);
- Return
JavaScript. Regular Expression
- JS: RegExp Tutorial
- JS: Regex Functions
- JS: Create Regex Object
- JS: RegExp Syntax
- JS: RegExp Flag
- JS: Regex Replace String Dollar Sign
- JS: Regex Replace Function Args
- JS: RegExp (class)
- 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