我正在试图弄清楚如何编写一个正则表达式,它返回单词"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".)
发布于 2015-02-24 06:39:14
使用表示单词边界的\b
。例如,\bAI\b
。
发布于 2022-02-17 19:13:32
您也可以对此实例使用\b(AI)\b
。
https://stackoverflow.com/questions/28684902
复制相似问题