admin管理员组

文章数量:1290090

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

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

Share Improve this question edited Jan 4, 2011 at 5:52 David Tang 93.7k32 gold badges168 silver badges149 bronze badges asked Jan 4, 2011 at 2:05 MosheMoshe 58.1k80 gold badges277 silver badges430 bronze badges 4
  • (?<=.*)(O|o)(I|i|y|Y) Will this suffice? It catches Oy or oy or Oi or oi. Hope it helps – Machinarius Commented Jan 4, 2011 at 2:12
  • @Drknezz You need a (\smate)? at the end :) – alex Commented Feb 15, 2011 at 2:25
  • @alex O: Dont know what those options are... :p – Machinarius Commented Feb 16, 2011 at 2:20
  • @Drknezz It's an Australian thing :) – alex Commented Mar 31, 2011 at 1:45
Add a ment  | 

3 Answers 3

Reset to default 13

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.

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?

本文标签: javascriptWhat regular expression would I use to find the word quotoyquotStack Overflow