我想在任何地方匹配一个包含2个字母p
的文字。
那么应该匹配什么
pp
xppm
xpxpm
ppm
和什么不匹配
ppp
xpxpxp
mpphellop
答案 0 :(得分:1)
使用此正则表达式:
^[^p]*p[^p]*p[^p]*$
解释
^ # from start
[^p]* # non 'p' characters from 0 to unlimited
p # the first 'p' character
[^p]* # non 'p' characters from 0 to unlimited
p # the second 'p' character
[^p]* # non 'p' characters from 0 to unlimited
$ # till the end
希望它有所帮助。