test is use in js for searching a regex patter. it is a selfish function so it would come first and the pattern which is to be matched would be comming after it : )
let string = " Hello! my name is Gaurav ";let search = /Gaurav/;search.test(string);
one more thing to note test would return a boolean value
or operator here in Regex is same |
so if i have to search in a string i would type /meow|bark/
let string = "meow meow !! i am a cat";let search = /meow|cat/;searc.test(string);
ignoring things in life is a important task !! but how we can thing in regex ? like lower case or upper case ?
by simply adding a "i" in the end
let search = /meow/i;
it will match anything in place of that .
(let me explain )
/ca./ will match caa,cab,cat,..... any thing that is of 3 letters and start with ca.
what if i only want to match words betweeen [a-g] ? what should i do? then use it .
will do that