lets learn js by #REGEXP
regexp is a string that describes a pattern e.g
Email and Phone.
we can define it in two ways
1. let re = /hi/;
2. let re = new RegExp('hi');
regexp is a string that describes a pattern e.g
Email and Phone.
we can define it in two ways
1. let re = /hi/;
2. let re = new RegExp('hi');
let message = 'Hi, are you there? hi, HI...';
let re = /hi/gi;
let matches = [];
let match;
do {
match = re.exec(message);
if(match) {
matches.push(match);
}
} while(match != null)
console.dir(matches);
let re = /hi/gi;
let matches = [];
let match;
do {
match = re.exec(message);
if(match) {
matches.push(match);
}
} while(match != null)
console.dir(matches);
#replace syntax
1. let newStr = str.replace(substr, newSubstr)
2.let newStr = str.replace(substr | regexp, replacer);
3. function replacer(match, p1, p2, ..., offset, string);
1. let newStr = str.replace(substr, newSubstr)
2.let newStr = str.replace(substr | regexp, replacer);
3. function replacer(match, p1, p2, ..., offset, string);
