user3642171
user3642171

Reputation: 21

Regular expression to exclude part of a url?

I'm trying to create a regular expression for google analytics goals.

I need to match either of these 2 url fragments:

/order/map/egw/?code=somevalue

or

/order/map/egw/

But NOT this url:

/order/map/egw/consult/

Tried this:

/order/map/egw/$ | /order/map/egw/\?

and other variations but can't get it to match properly

Fast help greatly appreciated!

Upvotes: 1

Views: 2770

Answers (2)

Jonathan Benn
Jonathan Benn

Reputation: 3569

How about this regular expression?

/order/map/egw/(?!consult).*

If in the future you find that there's another sub-directory that you don't want to include, you can add a new one (e.g. the sub-directory 'wrong') like so:

/order/map/egw/(?!consult|wrong).*

Upvotes: 1

tenub
tenub

Reputation: 3446

What about this? I don't know how strict you're trying to be but it should work for your use cases:

(?!.*consult)/order/map/egw/(\?.+)?

It ensures "consult" is not found in the URL and matches the base part with an optional query string.

Upvotes: 0

Related Questions