问题描述
我想匹配包含单词oana"的所有单词.我在一些词中,在词首、词中和词尾放置了带有大写字母的OANA".
I want to match all the words that contains the word "oana". I put "OANA" with uppercase letters in some words, at the beginning, middle, and at the end of words.
blah OANAmama blah aOANAtata aOANAt msmsmsOANAasfasfa mOANAmsmf OANAtata OANA3 oanTy
反正我做了一个正则表达式,但不是很好,因为它没有选择所有包含oana"的词
Anyway, I made a regex, but it is not very good, because it doesn't select all words that contains "oana"
\b\w+(oana)\w+\b
谁能给我另一个解决方案?
Can anyone give me another solution?
推荐答案
您需要使用不区分大小写的标志并将 +
替换为 *
:
You need to use a case insensitive flag and replace +
with *
:
/\b\w*oana\w*\b/i
请参阅 regex 演示(可能会使用也可能不会使用全局修饰符,具体取决于正则表达式引擎).不区分大小写的修饰符可以在某些正则表达式引擎中作为内联选项传递 - (?i)\b\w*oana\w*\b
.
See the regex demo (a global modifier may or may not be used, depending on the regex engine). The case insensitive modifier may be passed as an inline option in some regex engines - (?i)\b\w*oana\w*\b
.
这里,
\b
- 一个词边界\w*
- 0+ 个字字符oana
- 单词内所需的字符字符串\w*
- 0+ 个字字符\b
- 一个词边界
\b
- a word boundary\w*
- 0+ word charsoana
- the required char string inside a word\w*
- 0+ word chars\b
- a word boundary
这篇关于正则表达式:匹配包含某个单词的所有单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!