[英]Python Regular Expression expression excluiding string containing pattern match
I want to create a regular expression to match url links that contain underscore character but I don´t what to match a specific string containing undercore. 我想创建一个正则表达式来匹配包含下划线字符的url链接,但我不想匹配包含下划线的特定字符串。 Bellow are some example with and without matchs indicated: 贝娄是一些有和没有匹配的例子:
"site.com/_price_" -> Match “site.com/_price_” - >匹配
"site.com/price" -> No Match “site.com/price” - >不匹配
"site.com/_Desde_" -> No Match - This is important “site.com/_Desde_” - >不匹配 - 这很重要
I have tried the following patterns without success 我尝试了以下模式但没有成功
"\[_](?!\_Desde_)"
"\(?!\_Desde_)\[_]"
"\[\_](^\_Desde\_)"
You may use 你可以用
_(?!Desde_)[^_]*_
See the regex demo 请参阅正则表达式演示
It matches 它匹配
_
- an underscore _
- 下划线 (?!Desde_)
- a negative lookahead that fails the match if the _
is followed with Desde_
substring (?!Desde_)
- 如果_
后跟Desde_
,那么匹配失败的负向前瞻 [^_]*
- 0+ chars other than _
[^_]*
- 除了_
以外的0+字符 _
- an underscore. _
- 下划线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.