regulkar expression
//padhne Tarika
//regex accepts the string as mentioned in regular expression and apply the regular expression
//functions and acts accordingly by looking the function working pattern
//scans the string word by word
console.log("working")
let regex=/^rajiv/ //if expression i.e string match with regex than it will gives true in down case else statement is executed
regex=/boy$/ //if ends with boy than it gives true:in eg. else but if /ege$/ if statement execution
regex=/r.ji/ //if there is any letter between a-z(only one could be any * / not necessarily be a-z) than scans the string and returns T or F
//in below case- if statement execution
regex=/r*jiv/ //more than one string in the given place. In the given case -if statement
regex=/ra?jiv/ //a is optional can accept with or w/o a :
//if /raj?iv?/ -----> j and v is optional: can accept: rai,raji,rajiv etc.
regex=/r\ajiv/ //must be a in the string------>
regex=/r\*jiv/ //must be * in the string - else statement
regex=/r[a-z]jiv/ //value could be from a-z-if statement
regex=/r[0-9]jiv/ //value could be from 0-9
regex=/r[0-9][A-Z]jiv/ //value could be from 0-9 and A-Z: accepts->r1Ajiv,r9Bjiv but
// r0ajiv doesn't match
regex=/r[abh]jiv/ //value could be a,b or h
regex=/ra{2}jiv/ //accepts value a exactly 2 times : raajiv -> in below case else statement
regex=/r{0,3}jiv/ //accepts value r 0-3 times: rrrjiv,rjv,jv,rrjv
regex=/(rjiv){3}/ //accepts rjiv exactly 3 times and same as other
let string=" is a good boy. rajiv studies in a good college"
let vari=regex.exec(regex)
console.log(vari)
if(regex.test(string)){
console.log(`${string} matches with ${regex.source}`)
}
else{
console.log(`${string} doesn't match with ${regex.source}`)
}
Comments
Post a Comment