簡體   English   中英

正則表達式和負面展望

[英]Regex and negative look ahead

我正在嘗試創建一些與網站域匹配的正則表達式模式。

規則如下:

For France, the URL pattern must have /fr-fr (followed by anything else) after the domain name, ie www.domain.com/fr-fr/anything
For Germany, the URL pattern must have /de-de (followed by anything else) after the domain name, ie www.domain.com/de-de/anything
And for all other countries, the URL pattern can be the root domain (ie www.domain.com) OR anything EXCEPT fr-fr and de-de after the domain name 

我有適用於法國和德國的以下Regex模式,它們工作正常:

https?://www.domain.com.*?/(?i)FR-FR.\*

https?://www.domain.com.*?/(?i)DE-DE.\*

但是,我正在努力獲得一個正則表達式模式,該模式將匹配根域和其他域(例如www.domain.com/en-us及其后的任何內容),但EXCLUDE /fr-fr.* and /de-de.*

我嘗試了負面的前瞻,例如這樣(例如,NOT France):

https?://www.domain.com.*?/(?!fr-fr).\*

但這似乎不起作用,並且與不應該匹配的URL匹配。

也許我缺少明顯的東西。

任何幫助,非常感謝。

僅“德國”網址:

^(?i)https?://www.domain.com(:\d+)?/de-de(/.*)?$

僅“法國”網址:

^(?i)https?://www.domain.com(:\d+)?/fr-fr(/.*)?$

既不是“德國”也不是“法國”的網址

^(?i)https?://www.domain.com(:\d+)?(?!/fr-fr|/de-de)(/.*)?$

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM