Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What regular expression would I use to find the word "oy"?

What is regular expression would I use to find the word "oy"? I need it to work in a userscript. Also, I have to make sure it doesn't remove words that contain "oy", like "Olive Oyl".

like image 408
Moshe Avatar asked Jan 04 '11 02:01

Moshe


2 Answers

You need /\boy\b/g.

Explanation:

The \b means word boundary (start or end of a word). The g on the end means to search for more than one occurence (global). Finally, if you want the search to be case insensitive, add an i after the g:

/\boy\b/gi

To remove all "oy" words in a string str, you do:

str.replace(/\boy\b/gi, "");
like image 171
David Tang Avatar answered Sep 17 '22 15:09

David Tang


/\boy\b/g

Will be the literal regular expression.

like image 26
alex Avatar answered Sep 20 '22 15:09

alex