How to combine regex if match and doesn't match substring?
Ex:
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
I want to get url which contain "user.php"
and "member.php"
BUT I don't want to get url if contain "context"
To match url if contain "user.php" and "member.php" I can use:
(user\.php|user\.php)
And if doesn't contain "context":
^((?!context).)*$
How to combine (user\\.php|user\\.php)
and ^((?!context).)*$
?
My results should be:
http://www.domain.com/user.php?query=blah
http://www.domain.com/member.php?query=blah
Thanks for help...
use this pattern
^(?=.*(?:user|member))(?!.*context).*$
make it:
^(?=.*\/(?: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).)*$
You can try this.See demo.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.