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 catchesOy
oroy
orOi
oroi
. 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
3 Answers
Reset to default 13You 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
版权声明:本文标题:javascript - What regular expression would I use to find the word "oy"? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741475049a2380832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论