简体   繁体   English

不以特定单词结尾的正则表达式

[英]Regex for not ending with specific words

I need to have a regex which matches the following -我需要一个匹配以下内容的正则表达式 -

/drama/uk
/drama/uk/
/drama/us
/drama/us/
/drama/fr
/drama/fr/

but should not match the following -但不应与以下内容匹配 -

/drama/uk-uk
/drama/uk-uk/
/drama/us-us
/drama/us-us/
/drama/fr-fr
/drama/fr-fr/

So far I have managed to get the first par working like this到目前为止,我已经设法让第一个标准杆像这样工作

/\/drama\/\uk|uk\/|us|us\/|it|it\/|fr|fr\/$/

But I don't know how to get the second part working.但我不知道如何让第二部分工作。 Can any one help please任何人都可以帮忙吗

You could use an anchor to start the string ^ , then match /drama/ and use an alternation with a non capturing group to list all the alternatives.您可以使用锚点开始字符串^ ,然后匹配/drama/并使用非捕获组的交替来列出所有备选方案。

The slash at the end can be optional.末尾的斜线可以是可选的。

^\/drama\/(?:uk|us|fr)\/?$

Regex demo正则表达式演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM