let regex = /harry/;
let str = "hrryt is good boy with hrr";
// let result = regex.exec(str);
// console.log("result is: ",result);
// result2 = regex.test(str)
// console.log("result2 is : ", result2);
// if(regex.test(str))
// console.log("string is matched");
// else
// console.log("string not matched");
// let look into metacharacter symbol
regex = /^harrdc/; // ^ means expression will match if string starts with
regex = /harry$/; // $ at the end of the string means "string ends with"
regex = /h.rry/; //matches any one character
regex = /h*rry/; //matches any 0 or more characters
regex = /ha?rryi?t/; //? after character means that character is optional
// regex = /h\*rry/;
if(regex.test(str))
console.log("string is matched");
else
console.log("string not matched");
0 Comments