简体   繁体   中英

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".

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

将是字面正则表达式。

I'd suggest trying /\\boy... Oh nevermind.

It is a bit hard to find questions easy enough to solve that haven't already been answered to death, right? Right?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM