【发布时间】:2021-09-18 01:35:39
【问题描述】:
我需要一个正则表达式来匹配以下条件:
NPT - match
@@#NPT -- match
@@#NPT*) -- match
testNPT -- not match
testNPTtest -- not match
@@NPT##test -- not match
.NPT. -- match
.NPT.abc -- not match
基本上,我需要匹配前缀和后缀不是字母或数字的单词(例如 NPT),但如果它是单个单词 (NPT) 或具有前缀或后缀或两者都只有特殊字符(例如 @ #NPT#$ 或 ##NPT)
我尝试了以下表达式,但没有得到想要的结果
(?<!^[a-z])(\bSM\b)(?![a-z])
【问题讨论】: