JS: RegExp.prototype.test
regex_obj.test(string)-
Return
trueif regex_obj match part or whole of string, elsefalse.If there is a regex flag
g, repeated call start from RegExp.prototype.lastIndex.console.log(/4/.test("345") === true); console.log(/4/.test("999") === false); // Repeated call with regex flag g. const xtext = "012x45x78x"; const xre = /x/g; console.log(xre.lastIndex); // 0 console.log(xre.test(xtext)); // true console.log(xre.lastIndex); // 4 console.log(xre.test(xtext)); // true console.log(xre.lastIndex); // 7
JavaScript. Regular Expression
- JS: Regular Expression Tutorial
- JS: Regular Expression Functions
- JS: Create Regex Object
- JS: Regular Expression Syntax
- JS: Regular Expression Flags
- 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