且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式匹配整个单词不工作

更新时间:2021-11-16 22:41:22

您将需要使用向后看,看看对字符串和空白的字符开始/结束提前匹配您。要匹配不一定会触发通常的字边界规则

You will need to use look behind and look ahead matches on beginning / end of string and whitespace as the characters you are trying to match won't necessarily trigger the usual word boundary rules.

使用(小于= ^ | \s?):D (= $ | \s?)这个模式应该为所有的比赛如的工作(小于= ^ | \s?):\)(= $ | \s)

use(?<=^|\s):d(?=$|\s) this pattern should work for all of your matches eg (?<=^|\s):\)(?=$|\s)