\b # word boundary, make sure we haven't a word character before
(?!p) # negative lookahead, make sure we haven't the letter "p" after
\w{2,} # 2 or more word character, make sure we don't match single letter
\b[^p\s]\w+
\b #word boundary, anchor to the beginning of a word
[^ ] #negated character class, matches any character except specified
p #literally "p"
\s #any whitespace character
\w #matches any word character
+ #quantifies previous expression between 1 and infinity times
你的正则表达式对我来说很好,你只需要匹配超过 1 个字母的单词:
\b(?!p)\w{2,}
解释:
截屏:
您正在寻找的是一个否定字符类 (
[^]
)。这会起作用:
解释:
请注意,不幸的是,这不匹配任何单个字符的单词,例如“I”。您可以将表达式修改为
\b[^p\s]\w+|(?<=\s)\b\w\b
.例子