2015-02-09 36 views
0

我試圖匹配以下的東西。正則表達式匹配數字的組合,但shuoldn't匹配一些其他模式

10/1987 - 10/1987 
2/1987 - 12/1987 
More clearly: 

["one" or "two digit"]["any symbol mainly [/-]][a space if there followed by slash or hiphen [-/]["one" or "two digit"]["any symbol mainly [/-]] 

這是我有的輸出。

https://regex101.com/r/cN9eJ0/1

+0

@vks - 只需在右側框中添加gmi即可。更新的鏈接是https://regex101.com/r/cN9eJ0/2 – user3116355 2015-02-09 09:28:09

回答

1
\b((?:(?<!\/)[\d]{1,2}[\/\s-]{0,3}(?!\d{3}\b)\d{2,4})\s*-\s*\b(?:(?<!\/)[\d]{1,2}[\/\s-]{0,3}(?!\d{3}\b)\d{2,4})) 

只需添加錨,以限制部分matches.See演示。

https://regex101.com/r/cN9eJ0/5

+0

它也匹配一些其他模式。 https://regex101.com/r/cN9eJ0/4 – user3116355 2015-02-09 09:37:49

+0

謝謝老兄。似乎乍一看工作。我會檢查更多的組合。 – user3116355 2015-02-09 09:42:19