This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var regex=/(?<circle>\d{2})(?<district>\d)[\s-]?(?<office>\d{3})/; | |
console.log(regex.exec("412207").groups); //{circle: "41", district: "2", office: "207"} | |
console.log(regex.exec("182-101").groups); //{circle: "18", district: "2", office: "101"} | |
console.log(regex.exec("224 123").groups); //{circle: "22", district: "4", office: "123"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str="\n9 " /* " | |
9 " */ | |
var regex=new RegExp("\n\\d\\s"); // /\n\d\s/ | |
regex.test(str); //true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str="\n9 " /* " | |
9 " */ | |
var regex=/\n\d\s/; | |
regex.test(str); //true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let x="abc"; | |
let re1=new RegExp(x); // output: /abc/ | |
let re2=/x/; // output: /x/ won't work as a variable in literal notation. | |
re1.test("abcdefg"); //true | |
re2.test("abcdefg"); //false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let re1=new RegExp("abc"); //output: /abc/ | |
let re2=/abc/; //output: /abc/ | |
re1.test("abcdefg") //true; | |
re2.test("abcdefg") //true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var name=" R e g E x p "; | |
var namewithoutspaces1=name.replace(" ",""); // "R e g E x p " | |
var namewithoutspaces2=name.replace(/\s/g,"");// "RegExp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var name=" R e g E x p" | |
let namewithoutspaces=name.split(" ").join(""); | |
console.log(namewithoutspaces); // "RegExp" |
NewerOlder