如何使用正则表达式查找包含某个字母的单词? [英] How to find words containing a certain letter with Regular Expressions?
本文介绍了如何使用正则表达式查找包含某个字母的单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个正则表达式来查找包含字母y"的任何单词.
I need a regular expression to find any words containing the letter "y".
这是我的想法:
/\bw*[y]\w*\b/
词边界,有或无,y,有或无,词边界.
它适用于第一个单词,但不适用于下一个.
a word boundary, something or nothing, y, something or nothing, word boundary.
It works for the first word, but not for the next one.
如何获取字符串中包含 y 的所有单词?
How do I get all the words containing a y within a string?
推荐答案
不知道您使用的是什么语言并根据您尝试的语法猜测,这应该有效:
Not knowing what language you're using and guessing based on the syntax of your attempt, this should work:
/\b\w*[Yy]\w*\b/g
如果没有 "g"(用于全局")选项获得第一场比赛.另请注意,这与大写和小写的y"匹配.
Without the "g" (for "global") option you'll only get the first match. Note also this matches on "y" in both upper and lower case.
这篇关于如何使用正则表达式查找包含某个字母的单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文