I need to modify this regex
href=\"(.*)\"
which matches this...
href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306"
To NOT match this...
href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306&returnurl=AbandonedVehicles.aspx"
Tried this, but with no luck
href=\"(.*)\"(?!&returnurl=AbandonedVehicles.aspx)
Any help would be much appreciated.
Thanks, Al.
The negative lookahead construct is the pair of parentheses, with the opening parenthesis followed by a question mark and an exclamation point. Inside the lookahead, we have the trivial regex u. Positive lookahead works just the same. q(?=u) matches a q that is followed by a u, without making the u part of the match.
Negative lookahead That's a number \d+ , NOT followed by € . For that, a negative lookahead can be applied. The syntax is: X(?! Y) , it means "search X , but only if not followed by Y ".
Positive lookahead: (?= «pattern») matches if pattern matches what comes after the current location in the input string. Negative lookahead: (?! «pattern») matches if pattern does not match what comes after the current location in the input string.
Lookahead assertions are part of JavaScript's original regular expression support and are thus supported in all browsers.
Lookaheads should be placed before the string is consumed by matching, i.e.
href=\"(?!.*&returnurl=AbandonedVehicles\.aspx)(.*)\"
href="(?!.*returnurl=AbandonedVehicles\.aspx)(.*)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With