I have a regex to track signups to my site. There could be multiple adresses for a goal.
Here is my regex:
(\/membership\/signed-up\/|\/membership\/campagin\/(?!.*(not-this-campaign)).[-\w]+\/signed-up\/)
I want to match this adresses:
/membership/signed-up/
/membership/campagin/random-campaign/signed-up/
/membership/campagin/other-random-campaign/signed-up/
But I want to exclude this address:
/membership/campagin/not-this-campaign/signed-up/
It works, but it google also matches this address:
/membership/signed-up/step-2/
When I test in http://regexr.com it matches only on the strings I want, but why is google analytics matching more?
Try this :
(\/MEMBERSHIP\/SIGNED\-UP\/(?!.*(STEP\-2))|\/MEMBERSHIP\/CAMPAGIN\/(?!.*(NOT\-THIS\-CAMPAIGN)).[-\w]+\/SIGNED\-UP\/)
You regex its almost correct, but, you need to ensure it dont match with STEP 2
Related
I'm trying to learn RegEx using ImmersiveLabs/LinkedInLearning and other web-based resources and things are going well.
There's a small question to which I'm not sure how to even Google for an answer.
Scenario, Azure ATP Query wherein I wanted to match Private Addressing Scheme
| where From_IP matches regex #'(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)'
It works well! Matches what I want it to. The question is - why?!
For e.g. (~172.2[0-9].) shouldn't this only match on the first two octets of the string 172.20.1.9 ? Why is then the entire IP matched successfully?
Seems weird for me to question something that is working. Any tips are appreciated.
There is no $ in your regex so your regex does not asserts position at the end of a line, so it basically doesn't care what comes after 172.20. , see for more info: regex101.com/r/TgjdVz/1
In addition to match all private IPv4 subnets use to following regex.
^(10(\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[0-9]{1,2})){3}|((172\.(1[6-9]|2[0-9]|3[01]))|192\.168)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[0-9]{1,2})){2})$
I don't usually use Regex. I'm working on Google Analytics Goals and I want to create a step in the funnel that will match URLs containing /resource/ and the word ebook or report, but do not include thank or thanks.
It would match:
/resource/example-ebook-request
/resource/research-report-2018/
It would not match:
/resource/example-ebook-request/thank-you/
/resource/research-report-2018/thanks/
/some-other-ebook-no-resource-subfolder/
I'm having a hard time getting the combination of this correct in a way that will work for Google Analytics since it doesn't support look behind. Any suggestions?
Try Regex: \/resource\/[^\/]*(?:ebook|report)[^\/]*\/?$
Demo
Let's say my domains are:
www.test.com
www.test.com/en-gb
www.test.com/cn-cn
These are language sites, the first is the main US English site. In Google Analytics I want to set up a filter to only show me traffic of the first (US) domain. I could do this, I think:
^\/(en-gb|cn-cn).*$
If I EXCLUDE my Request URI with that filter pattern, then I should get a view for the en-US domain. However, I'm interested in understanding regex better so here is some test data and code which I am trying out on http://www.regextester.com/
Regular expression:
^\/(en-gb|cn-cn).*$
Test String
/cn-cn/about
/cn-cn/about/
/cn-cn
/cn-cn/about/test
/en-gb/
/en-gb
/en-gb-test/
/en-gb/aboutus/
/en-gb?q=1
/en-gb/?q=1
/about-us
/test?q=1
/aword/me/
/three
/about/en-gb/
/about/en-gb-test/
/test-yes/
/test/me/
/hello/world/
My questions:
If you try this out, you'll notice that /en-gb-test/ is actually matched with the Regex. How do I avoid this?
Also, let's say I wanted to have a rule to NEGATE this whole option. So rather than telling Google Analytics to "exclude", I am curious how I could write the opposite of this same rule. So basically, catch all URLs that are not in /en-gb and /cn-cn sub-folders.
Thanks in advance!
You may stop the regex from matching en-gb-test by making sure you may / or ? after it or the end of the string
^\/(en-gb|cn-cn)([\/?]|$)
See the regex demo. If you really need to get the rest of the string, add .* after [\/?]: ^\/(en-gb|cn-cn)([\/?]|$).
Details:
^ - start of string
\/ - a / (note that you do not need to escape / in GA regex)
(en-gb|cn-cn) - a capturing group with 2 alternatives, either en-gb or cn-cn
([\/?]|$) - a capturing group with two alternatives: a ? or / OR the end of the string.
In RE2 regex, you cannot use lookaheads that are crucial when you need to match something other than something else. It would look like ^(?!\/(en-gb|cn-cn)([\/?]|$)).*, but it is not possible with RE2.
My Google Analtyics is victim of Ghost Spam, in particular is something which looks like
/?from=http://site-63162314-1.snip.tw/
/?from=http://site31946091.snip.tw/
/?from=http://site18623769.snip.tw/
I'd like to create a regex which will match the following string: site(something).snip.tw
After a read up on a few sites of how to use Regex, my effort is
.*site.*snip
This only fiters out the last in the list above (/?from=http://site18623769.snip.tw/) but oddly, it also filters out other URLs, such as ?from=http://share-buttons.xyz/ (which is fine) but sadly so has /MassageTherapy/DeepTissueMassage?cpc=dtm
Why does my regex not match the above 3 examples?
Currently on my GA Account I have the following URL's from our website tracked:
domain/contact-us/
domain/contact-us/global-contact-list.aspx
domain/contact-us/contactlist.aspx
The first two are from our new website which we want to track, the last one is from our old website (traffic is still being tracked but we do not want to use this)
I tried using a regex filter on this as the following:
(^/contact-us/global-contact-list\.aspx)|(^/contact-us/)
Reading up, I believe this looks for matches of exactly:
/contact-us/global-contact-list or /contact us/ but would disallow /contact-us/contactlist/
for some reason, the above one is still coming through. Can someone please see as to why this may be happening or know why this is happening?
You need to add a negative look-behind or a end of string anchor:
(^/contact-us/global-contact-list\.aspx)|(^/contact-us/$)
or
(^/contact-us/global-contact-list\.aspx)|(^/contact-us/(?!contactlist/))
This way, you will exclude /contact-us/contactlist/ from matching.
Have a look at the Demo 1 and Demo 2.
BTW, /contact us/ will not pass since (^/contact-us/) only allows a hyphen. You should add a space, e.g. (^/contact-us/global-contact-list\.aspx)|(^/contact[-\s]us/$).
Also, (^/contact-us/global-contact-list\.aspx) won't match /contact-us/global-contact-list because it needs to match .aspx.