splunk
splunk

Reputation: 6815

regex - find out strings that contains one word or its substring not followed by a certain character

I should match any strings that contains "checkout" or "checkout.html" not followed by "?" with regex.

For example:

www.xxx.com/en/cp/checkout.html?basket_gotostep=4  FALSE
www.xxx.com/en/cp/checkout.html=test  OK
www.xxx.com/en/cp/checkout=test_23   OK
www.xxx.com/en/cp/checkout?basket_gotostep=4 FALSE

This is what I've tried:((checkout\.html)(?!\?))|((checkout)(?!\?)) but it doesnt work.

Upvotes: 1

Views: 148

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627607

You may use a regex like

\bcheckout\b(?!(?:\.html)?\?)

Or

\/checkout\b(?!(?:\.html)?\?)

See the regex demo

Details

  • \/checkout\b - /checkout followed with a word boundary check
  • (?!(?:\.html)?\?) - a negative lookahead that fails the match if, immediately to the right of the current location, there is an optional .html sequence followed with a ? char.

Upvotes: 1

Related Questions