جاوا اسکریپت روزانه
2 subscribers
1 link
این چینل روزانه مطالبی در مورد جاوا اسکریپت به نشر می رساند
Download Telegram
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');
g. global
i. ignore
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);
#methodes for regexp
1. replace
2.search
3.match
#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);