如何重新匹配模式,但排除?

时间:2021-08-27 18:45:38

I have а sequence like:

我有а序列:

0-2014
1-2014
2-2014
...
11-2014
12-2014
0-2015
0-2016
0-2017
...

I need match any of them but with exclusion 0-2014

我需要匹配其中任何一个,但排除0-2014

Now I have only common way without exclusion:

现在我只有一个共同的方法,没有排斥:

(([0-9]{1,2})-20([0-9]{2}))

So the question: is it possible to exclude 0-2014 from matching? And How?

所以问题是:是否有可能将0-2014排除在匹配之外?以及如何?

2 个解决方案

#1


2  

You can use a negative look ahead :

你可以用消极的展望:

((?!0-2014)([0-9]{1,2})-20([0-9]{2}))

DEMO

演示

Also if you don't need inner groups you can use non capture-grouping for them :

另外,如果你不需要内部团队,你可以使用非分组的方法:

((?!0-2014)(?:[0-9]{1,2})-20(?:[0-9]{2}))

#2


1  

You can use the following:

你可使用以下资料:

(?!0-2014)(([0-9]{1,2})-20([0-9]{2}))

See DEMO

看到演示

#1


2  

You can use a negative look ahead :

你可以用消极的展望:

((?!0-2014)([0-9]{1,2})-20([0-9]{2}))

DEMO

演示

Also if you don't need inner groups you can use non capture-grouping for them :

另外,如果你不需要内部团队,你可以使用非分组的方法:

((?!0-2014)(?:[0-9]{1,2})-20(?:[0-9]{2}))

#2


1  

You can use the following:

你可使用以下资料:

(?!0-2014)(([0-9]{1,2})-20([0-9]{2}))

See DEMO

看到演示