Javascript Regular Expressions Static Properties

Description

Javascript Regular Expressions Static Properties


let myRegexp = /Java(Script)?/g;
let myString = "Both Java and JavaScript share the same name, but are quite different.";

myRegexp.exec(myString);//w  ww.  j  av  a 2  s. c  om
myRegexp.exec(myString);
// Now we're at position 24

console.log( RegExp.input );  // "Both Java and JavaSc.." - the entire string
console.log( RegExp.lastMatch );  // "JavaScript"
console.log( RegExp.lastParen );  // "Script"
console.log( RegExp.leftContext );  // "Both Java and"
console.log( RegExp.rightContext);  // "share the same name, but are quite different."

console.log( RegExp["$_"] );  // "Both Java and JavaSc.." - the entire string
console.log( RegExp["$&"] );
console.log( RegExp["$+"] );
console.log( RegExp["$'"] );
console.log( RegExp["$'"] );  



PreviousNext

Related