Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Catch URL with parameters or end of URL using regular expression

I’m trying to figure out how to capture some URL patterns with regular expression in Google Analytics, but I have not yet figured out how.

Here are some example URLs:

url1: myurl.com/dir1/dir2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

url2: myurl.com/dir1/dir2?myparam=1

url3: myurl.com/dir2/dir2/anotherdir/

I would like to be able to capture the two first ones but not the last one and then the last one but not the two first ones.

I tried for example:
(myurl.com/dir1/dir2$|myurl.com/dir1/dir2?) -> I get url1 but not url2

myurl.com/dir1[^/] -> doesn’t work

myurl.com/dir1? -> doesn’t work

myurl.com/dir1/ -> capture url 3

So capturing url3 only is easy but I don’t see how to capture url1 and url2.

>Solution :

If I understand correctly, can’t you just use this for the first two:

myurl\.com\/dir1\/dir2($|\?.+)

And use this for the last:

myurl\.com\/dir2\/dir2\/.+

I noticed that you are not using any escape characters. You should escape reserved characters with backslash.

You can use https://regex101.com/ to get detailed explanation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading