Javascript Regex check if URL contains one word AND does NOT contain another -
How can a URL check if there is a specific word in it, but also see if there are no words in it? If I try to try and display an example then it would be better:
Do something if the ' pan ' is in the URL, then the word ' Panini 'url has: The first part above works fine, but with the other part, will there be no work in it, does anyone have any ideas? returns a boole, so just It can be simplified to use (should be fast):
if (/pan/.test(self.location.href) & amp; (/ panini /.test(self.location.href) = = Null) {...}
! Use operator:
if (/pan/.test(self.location.href) & amp; (/ Panini / .test (self.location.href)) { ...}
if (self.location.href. IndexOf ("pan") & gt; -1 & amp; amp; amp; & amp; amp; self.location .href.indexOf ("panini") == -1) {...} < P> Additionally, you can use a regex test term limit for one word,
\ b :
/ \ bpan \ b / .test (self .locati On.href) // "Pan" will match "Pan and food", but "Panini" will not be
Comments
Post a Comment