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".
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, "");
/\boy\b/g
Will be the literal regular expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With