Solution: Regexp - select everything before the 3rd slash

Development | Programming languages
Author
Description

What would be the easiest regexp selecting all before the 3rd slash

I tried this:

([^\/?#]+){3}(?:.*?\/)

But it does not work exactly as I would hope it would do. Whats more i dont know that it will work in Google Analytics (Filter Section)

Attachments
No attachments.
Solutions

What you might do instead is ot repeat matching 2 times not a forward slash and then a forward slash.

^(?:[^\/]*\/){2}[^\/]+

See a regex demo

If you don't want to match ?# you could add that to the character class

^(?:[^\/?#]*\/){2}[^\/]+

About your pattern

This part of your pattern ([^\/?#]+){3} captures in a group matching 1+ times any character that is not in the character class but after that repetition takes no forward slash into account.

Then (?:.*?\/) will match any character non greedy followed by a forward slash.


on May 06th, 2019 (9:34 pm)
What masters said
You must sign in to comment!!
All comments
This solution has not been commented yet.