Basic Regular Expression URL Matching - regex

Im in the process of learning regular expressions but still cant really wrap my head around it quite yet. However I need to create one for Google Analytics and was hoping someone could help out.
Currently my Goal page is head-match:
/checkout/cart?complete
and funnel step:
/checkout/onepage
The problem is that the funnel step could be several different slightly different URLs. It could be:
/checkout/onepage
/checkout/onepage/index
/checkout/multishipping/login
/checkout/multishipping/billing
/checkout/multishipping/shipping
Can anyone tell me what the expression would be to "lump" those 5 potential URLs as the same thing? Also, what would I change my Goal url to if the potential outcomes could be one of the below examples:
/checkout/cart?complete=10000245 <-- (single order)
/checkout/cart?complete=10000245,10000246,10000247 <-- (multiship order)
I know I would have to escape the question mark first but after that Im not sure.

For your goal page you'll want to use the + ? and * operators.
/checkout/cart\?complete(=(\d+,?)*)?
For funnel you'll want the | and ? operators
/checkout/(onepage(/index)?|multishipping/(login|billing|shipping))

Related

How to Keep rows of multi-line cells containing a keyword in google sheets

I'm trying to keep lines that contain the word "NOA" in a column A which has many multi-line cells as can be viewed in this Google Spreadsheet.
If "NOA" is present then, I would like to keep the line. The input and output should look like the image which I have "working" with too-many helper cells. Can this be combined into a single formula?
Theoretical Approaches:
I have been thinking about three approaches to solve this:
ARRAYFORMULA(REGEXREPLACE - couldn't get it to work
JOIN(FILTER(REGEXMATCH(TRANSPOSE - showing promise as it works in multiple steps
Using the QUERY Function - unfamiliar w/ function but wondering if this function has a fast solution
Practical attempts:
FIRST APPROACH: first I attempted using REGEXEXTRACT to extract out everything that did not have NOA in it, the Regex worked in demo but didn't work properly in sheets. I thought this might be a concise way to get the value, perhaps if my REGEX skill was better?
ARRAYFORMULA(REGEXREPLACE(A1:A7, "^(?:[^N\n]|N(?:[^O\n]|O(?:[^A\n]|$)|$)|$)+",""))
I think the Regex because overly complex, didn't work in Google or perhaps the formula could be improved, but because Google RE2 has limitations it makes it harder to do certain things.
SECOND APPROACH:
Then I came up with an alternate approach which seems to work 2 stages (with multiple helper cells) but I would like to do this with one equation.
=TRANSPOSE(split(A2,CHAR(10)))
=TEXTJOIN(CHAR(10),1,FILTER(C2:C7,REGEXMATCH(C2:C7,"NOA")))
Questions:
Can these formulas be combined and applied to the entire Column using an Index or Array?
Or perhaps, the REGEX in my first approach can be modified?
Is there a faster solution using Query?
The shared Google spreadhseet is here.
Thank you in advance for your help.
Here's one way you can do that:
=index(substitute(substitute(transpose(trim(
query(substitute(transpose(if(regexmatch(split(
filter(A2:A,A2:A<>""),char(10)),"NOA"),split(
filter(A2:A,A2:A<>""),char(10)),))," ","❄️")
,,9^9)))," ",char(10)),"❄️"," "))
First, we split the data by the newline (char 10), then we filter out the lines that don't contain NOA and finally we use a "query smush" to join everything back together.

How to I make gerrit query that spans across few specific projects?

I tried for few hours to find the right syntax for making a regex query that returns reviews from 2-3 different projects but I failed and decided to crowdsource the task ;)
The search is documented at https://review.openstack.org/Documentation/user-search.html and mentions possible use of REGEX,... but it just didn't work.
Task: return all CRs from openstack-infra/gerritlib and openstack-infra/git-review projects from https://review.openstack.org
Doing it for one project works well project:openstack-infra/gerritlib
Ideally I would like to look for somethign like ^openstack-infra\/(gerritlib|git-review), or at least this is the standard regex syntax.
Still, I found impossible to use parentheses so far, every time I used them it stopped it from returning any results.
1) You don't need to escape the "/" character.
2) You need to use double quotes to make the parentheses work.
So the following search should work for you:
project:"^openstack-infra/(gerritlib|git-review)"

jmeter extract multiple regular expression

I'm looking to extract 2 expressions from the following response:
"FirstValue":"1234","Someotherfield":"****","Someotherfield":"****",(Some other more fields),"SecondValue":"6789"
Now explained deeply: there is my first value - which is followed by many other values, and eventually my second value. Note: the number of fields between is defined and determined, but I don't use the following solution:How to extract multiple values with a regular expression in Jmeter because I think it will be too long regular expression (about 20 back slashes).
I've come up with the following 2 solutions:
Reference name: Parameters
1."FirstValue":"(.+?)"(.+?)"SecondValue":"(.+?)"
2."FirstValue":"(.+?)"*.*"SecondValue":"(.+?)"
Which work fine. But, I want to make it more efficient, since in the response I get also the value between my requested values (e.g. Parameters_g0="FirstValue":"1234","Someotherfield":"****","Someotherfield":"****",(Some other more fields),"SecondValue":"6789").
So question is, is there a more efficient way to use? If no, which one is preferred between what I raised in this post?
Thank you

Grails Filter regexs

I am new to grails and so far i have only been able to use simple filters. I want to use filter in an efficient manner.
(I am using grails 2.4.3, with jdk_1.6)
I want to create a filter to allow accessing AppName/ and AppName/user/login and i could not get it right! I wanted to use regex but i am not getting it right!
i tried this
loggedInOnly(uri:'/**',uriExclude :"*.css|*.js|*image*|/|/user/login"){
before = {
println "### ###### #### #"
}
}
and i also tried to revers the regex parameter, but i am getting no luck! I searched all of google but i could not find a single thread to tell me how filter regex work!
i know i could create xxxx(controller:'*', action:'*') filter then use the controllerName and actionName parameters to check! But there gotta be a better way!
My question in a nutshell: How does regex work in filters?
First, take a closer look at the documentation. Notice that uri and uriExclude are ant paths and not regular expressions. Keeping that in mind if you look how ant paths function you will see they aren't capable of logical ors.
So, with all of that in mind it's back to using enabling regex and using the find attribute instead.
loggedInOnly(regex: true, find: '(.​*.css|.*.js|.*image.*|\\/|\\/user\\/login)​', invert: true){
before = {
...
}
}
Notice I hae used invert to have this filter apply to anything that doesn't match any of the patterns inside the find. Also, I wrote this off the top of my head so you may have to spot check the regular expression in your application (I did check it using groovy web console to make sure I didn't really mess up the syntax).
Hope this helps.

Using Regex to find multiple values (groups) in webpage

I'm trying to retrieve 2 fields from a web page. I'm using the following two patterns:
string paternExperience = #"Experience\s\:\s\<strong\>(?<Level>.*?)\<";
string paternAccount = #"account_value\""\>(?<Account>.*?)\<";
and the following method to retrieve values and it works.
Regex.Matches(pageBody, patern..., RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled |RegexOptions.Multiline);
I was trying to avoid using twice the method to retrieve 2 values, and I'm trying to create a pattern to get Level and Account in just one call of the Matches method. So I thought that something like the one below should work...
string paternBoth = #"Experience\s\:\s\<strong\>(?<Level>.*?)\< .* account_value\""\>(?<Account>.*?)\<";
But it doesn't work because I think that the two values are on diferent lines in html, so I added RegexOptions.SingleLine and now the method times out (the page has around 20kb).
Can you help me please with some advice? Thank you!
You could try putting those 2 values in 1 variable, then just check that variable with your regex.
I know it doesnt really make any sense but I try out things like that and sometimes it actually works.
Never had this scenario but I did have any simular problems in the past.
Might not be the best way. but sometimes making it work is more important then making it look pretty. ;)