我想弄清楚如何编写一个返回单词“AI”而不返回包含“ai”的单词的正则表达式。
我的猜测是,仅当“ai”左侧有一个空格且“ai”右侧有一个空格时,我才需要使用返回“ai”的运算符。
但允许在两端使用标点符号。
目标是返回如下搜索结果:
"AI, the future of computing"
or
"Has AI finally arrived?"
as opposed to
"He said what?" (Notice ai is within the word "said".)
最佳答案
使用 \b
表示单词边界。
例如。 \bAI\b
.
关于javascript - 如何使用正则表达式搜索术语 "AI",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28684902/