注册表项为";或/或";,但不是";既不是";也不是"; [英] Regexp for "either/or" but not "neither"
本文介绍了注册表项为";或/或";,但不是";既不是";也不是";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此处使用记事本++v7.9。
假设R
是一个复杂的regexp模式。我现在希望匹配_R
、R_
或_R_
,但不是只匹配R
。如何在不显式编写(_R|R_|_R_)
的情况下做到这一点?这需要将R写出三次,并且看起来很难看。
我能想到的最接近的是_?R_?
,但这也只与R
匹配(实际上相当于R
),这对我来说是假阳性。
介于(_?R_|_R_?)
之间的是R
,但此处再次重复R
,不过少了一次。
推荐答案
您可以按如下方式使用If-Then-Else:
(_)?R(?(1)_?|_)
Demo。
这使您可以只写入R
一次。
明细:
(_)? # An optional capturing group that matches an underscore character.
R # Matches 'R' literally (replace it with your pattern).
(? # If...
(1) # ..the first capturing group is found,...
_? # ..then match zero or one underscore characters (optional).
| # Else (otherwise)...
_ # Match exactly one underscore character (required).
) # End If.
在记事本++中工作:
这篇关于注册表项为";或/或";,但不是";既不是";也不是";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文