正则表达式:查找范围,除了一个字母或范围 [英] Regular expression: find range except for one letter or a range
问题描述
如何使用方括号内的否定作为例外,找到e。 G。 a-z之间的一切除了m-o的范围之外? [az ^ mo]
?
提前感谢!
顺便说一下:我不是为了这个例子而是要求,而是能够在范围内排除范围,甚至排除范围内的单个字母。我非常清楚,在这个例子中,它可以被计算...;)再次感谢你提前!
我使用Zend引擎(PHP) / p>
你应该可以自己计算差价。
[a-lp-z]
如果正则表达式引擎支持先知断言,您可以使用
(?![mo])[az]
/ pre>
但这可能效率较低。
How can I use the negation within square brackets as an exception, to find e. g. everything between a-z except for the the range from m-o?
[a-z^m-o]
?Thanks in advance!
By the way: it's not for the sake of this example that I ask, but to be able to exclude ranges within ranges, or even single letters within ranges. I am pretty much aware that in this example it can be calculated... ;) Once again, thanks in advance!
I use the Zend engine (PHP).
解决方案You should be able calculate the difference yourself.
[a-lp-z]
If the regex engine supports lookahead assertion, you could use
(?![m-o])[a-z]
but this would probably be less efficient.
这篇关于正则表达式:查找范围,除了一个字母或范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!