Sunday, 15 July 2012

javascript - How to REGEX match and doesn't match substring -



javascript - How to REGEX match and doesn't match substring -

how combine regex if match , 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 url contain "user.php" , "member.php" don't want url if contain "context"

to match url if contain "user.php" , "member.php" can use:

(user\.php|user\.php)

and if doesn't contain "context":

^((?!context).)*$

how combine (user\.php|user\.php) , ^((?!context).)*$ ?

my results should be:

http://www.domain.com/user.php?query=blah http://www.domain.com/member.php?query=blah

thanks help...

use pattern ^(?=.*(?:user|member))(?!.*context).*$ create it:

^(?=.*\/(?:user|member)\b\.php)(?!.*context).*$

demo

^ # begining of string (?=.*\/(?:user|member)\.php) # ahead "/user.php" or "/memeber.php" (?!.*context) # negative ahead "context" .*$ # end

javascript php regex match

No comments:

Post a Comment