Comments on: Regex to Match Number of Subdirectories in a URL https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/ APIs, Sheets, and Analytics Thu, 25 Feb 2021 08:45:48 +0000 hourly 1 https://wordpress.org/?v=6.5.2 By: Ivan O https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-20112 Fri, 30 Oct 2020 10:31:01 +0000 http://mixedanalytics.com/blog/?p=1736#comment-20112 Hello Ana,

This is really helpful.

Thanks a lot
Ivan

]]>
By: Lars https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-18734 Tue, 25 Aug 2020 08:05:16 +0000 http://mixedanalytics.com/blog/?p=1736#comment-18734 In reply to Lars.

Turns out I made a mistake. It works fine, probably stared at this too long at once. Even more thanks now!

]]>
By: Lars https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-18733 Tue, 25 Aug 2020 07:35:17 +0000 http://mixedanalytics.com/blog/?p=1736#comment-18733 Thank you so much for this article! I had a few headaches getting my head around how to do this properly, but thanks to your examples I've managed to get a clean grouping in Google Analytics.

However... the headaches are starting again now I want to use it in Datastudio. I've changed the regex to match datastudio's regex version (Google RE2). However, the regex doesn't exclude url strings with more than 3 directories. It now works as a minimum of 3 directories. I'd like to exclude url strings with 4 or more directories, so I only have the url strings with 3 directories.

Do you happen to have an idea how to do this in Google RE2 for Datastudio?

Thanks for your help! 🙂

]]>
By: dajaj https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-16769 Fri, 15 May 2020 09:28:50 +0000 http://mixedanalytics.com/blog/?p=1736#comment-16769 Thanks a bunch - exactly what i needed.

]]>
By: Ana https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-16157 Tue, 28 Apr 2020 04:51:59 +0000 http://mixedanalytics.com/blog/?p=1736#comment-16157 In reply to Sourabh.

I'm not sure I totally understand your question, but GA doesn't support negative lookahead regex, so in general you need to choose simple conditions that include the text you want, and exclude the text you don't. So in your example, a regex condition of "/category/" would naturally exclude "/subcategory-2/" since the string doesn't include "-2" in it.

]]>
By: Sourabh https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-16130 Mon, 27 Apr 2020 15:37:52 +0000 http://mixedanalytics.com/blog/?p=1736#comment-16130 I am trying to set up goals in ga and want to track the following way
Suppose I have http://www.abc/Category/Subcategory/Products1
http://www.abc/Category/Subcategory/Products2
http://www.abc/Category/Subcategory-2/Product-1
http://www.abc/Category/Subcategory-2/Product-2
I want to track Only Category , Subcategory , Products
I want to Track Home Page --> Category Pages ---> Subcategory Pages ---> Products To be configured as goals in Ga . I need to know in my destination url how Do I do this so I can include multiple categories excluding sub then
multiple subs excluding products or categories and like wise

]]>
By: Ana https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-12308 Sat, 14 Dec 2019 05:12:25 +0000 http://mixedanalytics.com/blog/?p=1736#comment-12308 In reply to TB.

Thank you for sharing! Though, your regex will only work for the specific case where the URL ends with some known string (like your '.aspx' example). If you want something a little more generalizable I think you could use this to match no directories: ^/[^/]+[a-zA-Z0-9]$

]]>
By: TB https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-12298 Fri, 13 Dec 2019 21:12:14 +0000 http://mixedanalytics.com/blog/?p=1736#comment-12298 Hi Ana. And here is the regex to match no directories: http://www.mywebsite.com/page.aspx
^\/[^\/]+\.aspx

]]>
By: AF https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-11872 Thu, 21 Nov 2019 15:02:12 +0000 http://mixedanalytics.com/blog/?p=1736#comment-11872 In reply to Ana.

This worked - and I'm kicking myself for not seeing it. Thank you!!

]]>
By: Ana https://mixedanalytics.com/blog/regex-match-number-subdirectories-url/#comment-11871 Thu, 21 Nov 2019 14:45:12 +0000 http://mixedanalytics.com/blog/?p=1736#comment-11871 In reply to AF.

Hey AF, sure, you can use .* as a wildcard.

So if you want to match on /abc/ and /123, you'd use the following expression: /abc/.*123

(I left the slash off the 123 so the regex will work even if it's immediately following /abc/.You can test it in your All Pages report to make sure it pulls in the URLs you're looking for.)

]]>