[英]How to REGEX match and doesn't match substring
如果匹配和不匹配子字符串如何合并正则表达式?
例如:
http://www.domain.com/user.php?query=blah
http://www.domain.com/member.php?query=blah
http://www.domain.com/user.php?query=blah&context=DkUdh8ShTkNNkwoIJkl
http://www.domain.com/member.php?query=blah&context=DkUdDh8ShTaDfkNNkwoIJkl
我想获取包含"user.php"
和"member.php"
URL,但是如果包含"context"
我不想获取URL
要匹配包含“ user.php”和“ member.php”的网址,我可以使用:
(user\.php|user\.php)
并且如果不包含“上下文”:
^((?!context).)*$
如何合并(user\\.php|user\\.php)
和^((?!context).)*$
?
我的结果应该是:
http://www.domain.com/user.php?query=blah
http://www.domain.com/member.php?query=blah
感谢帮助...
使用这种模式
^(?=.*(?:user|member))(?!.*context).*$
做了:
^(?=.*\/(?:user|member)\b\.php)(?!.*context).*$
^ # begining of string
(?=.*\/(?:user|member)\.php) # look ahead for "/user.php" or "/memeber.php"
(?!.*context) # negative look ahead for "context"
.*$ # anything to the end
^(?=.*?(?:\buser\b|\bmember\b)\.php)(?:https?:\/\/)?[^/]*/(?:(?!context).)*$
您可以尝试一下。请参阅演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.