Jmeter regex extractor alternate option for lookbehind - regex

I am trying to extract the value of session id from the response header.Is there an alternate way other than using lookbehind in jemeter?
I verified my regex in regexformatter and its working as expected but as jmeter is not supporting lookbehind, the solution is not working for me.
Response header :
Expires: 0
X-Frame-Options: DENY
x-session-id: 1a5e099f-5234-4
X-Application-Context: test:8080
Regex used is:
(?<=x-session-id: ).{0,16}
Can someone help me with it?

As per Regular Expressions chapter of the JMeter User Manual:
Note that (?<=regexp) - lookbehind - is not supported.
So you can just use something like: x-session-id:\s+(.+) and it should work fine:
More information: Using Regular Expressions to Extract Tokens and Session IDs to Variables

The Regular Expression Extractor configuration should be this one:
Regex:
x-session-id: (.*)

Assuming that the last character in the session id will be digits. Then you can use the following. If you think the second group in session id will be digits then replace second \w+ with \d+ and it will serve the purpose. Let me know if you think the other dataset may fail this regex.
Regex:(?:\w+-\w+-\d+)
Seems like you have an understanding about Regex so not mentioning the explanation. Let me know if this does not work for you. I will try to come up with another approach but in that scenario please give more datasets. Good Luck.

Related

Regex on domain and negation against language subfolders

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.

Regex: Extract string between two strings

This is the issue I face
The String
nt/sign-in?wa=wsignin1.0&wtre
The Need
From that string I need to extract the following
wsignin1.0
The Attempts
So far I have tried the following Regex
wa=(.*?)(?=&amp)
This returns:
wa=wsignin1.0
The "wa=" is not supposed to be there
Perhaps with a look behind?
(?<=wa\=)(.+)(?=\&wtre)
wsignin1.0
JMeter uses Perl5-style regular expressions therefore the regex you are looking for might be as simple as:
wa=(.+?)&wtre
Demo:
Use $1$ as "Template" in your Regular Expresssion Extractor.
See How to Debug your Apache JMeter Script for more details on JMeter tests troubleshooting.
=([\w.]++)
will capture it in the first capture group. Otherwise I think #jivan has a good idea with the lookbehind. A little tweak too it:
(?<==)[\w.]++
Put this in your Regular Expression extractor:
nt/sign-in?wa=([a-zA-Z0-9\.]*)&wtre
I hope this help you.

Regular expression not working in google analytics

Im trying to build a regular expression to capture URLs which contain a certain parameter 7136D38A-AA70-434E-A705-0F5C6D072A3B
Ive set up a simple regex to capture a URL with anything before and anything after this parameter (just just all URLs which contain this parameter). Ive tested this on an online checker: http://scriptular.com/ and seems to work fine. However google analytics is saying this is invalid when i try to use it. Any idea what is causing this?
Url will be in the format
/home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd
so i just want to capture URLs that contain that specific "z" parameter.
regex
^.+(?=7136D38A-AA70-434E-A705-0F5C6D072A3B).+$
You just need
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B.+$
Or (a bit safer):
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&.+$)
And I think you can even use
=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&)
See demo
Your regex is invalid because GA regex flavor does not support look-arounds (and you have a (?=...) positive look-ahead in yours).
Here is a good GA regex cheatsheet.
To match /home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd you can use:
\S*7136D38A-AA70-434E-A705-0F5C6D072A3B\S*

Use Regex to match beginning and end part of URL in Google Analytics

I'm looking for a regex function to implement in a goal for Google Analytics.
Consider this URL: /dagje-uit/....variable part..../contact/vpv/bedankt
Regex should work when beginning of URL matches /dagje-uit/ and end part contains /contact/vpv/bedankt Everything in the middle can be variable.
Without result i've tried
(?=^/dagje-uit/.*)(?=.*/bedankt$).*
(?=^dagje-uit.*)(?=.*bedankt$).*
Thanks in advance!
Regards,
Pim
Forgive me if Google Analytics has some regex standards which I am overlooking but is it possible that your regex is failing because it does not account for the start of the whole of the URL? Adding .* to either end of your regex may help.
It also looks like your regex is over-complex for the conditions you have described. Could a simpler match be :
.*/dagje-uit/.*/contact/vpv/bedankt.*
or
http(s)?://.*/dagje-uit/.*/contact/vpv/bedankt.*
if you want to be a little more confident that it is a valid URL.

Filtering Google Analytics API with Regex - Stop Before a Character (query string)

I'm working with Google Analytics API add-on for Google Spreadsheets to pull in data.
I know basic regex and it turns out that negative lookbacks / not operators (I'm assuming they're the same?) aren't allowed in Google Analytics, therefore I'm having difficulty with this filter.
I want to filter out all URL page paths that have a query string in them. Here's a sample list:
/product/9779/this-is-a-product
/product/27193/this-is-a-product-with-a-query-string?productId=50334&ps=True
/product/281727/this-is-another-product-with-a-really-long-title
/product/979
/product/979/product-12-pump-septic
/product/9790/the-1983-ford-sedan
/product/9791/remington-870-3-express-410-pump-shotgun
/category/2738/this-is-a-category
I want my output to be:
/product/9779/this-is-a-product
/product/281727/this-is-another-product-with-a-really-long-title
/product/979/product-12-pump-septic
/product/9790/the-1983-ford-sedan
/product/9791/remington-870-3-express-410-pump-shotgun
This is the start of my Regex...
ga:pagePath=~^/product/(.*)/
...which ignores the fourth line but I have no idea what to put after the second backslash.
I've tried a few things here (like this one Regular expression to stop at first match) and have been testing my code here (http://www.analyticsmarket.com/freetools/regex-tester).
Any insight would be greatly appreciated!
You can use the following regular expression to match the desired output.
^/product/.*/[\w-]+$
Live Demo
Try this also. It will strictly capture. what you need.
^\/product\/((?:(?!\/|[a-z]).)*)\/[\w-]+$
SEE DEMO : http://regex101.com/r/gS3lF8/2
^/product/\d+/[a-zA-Z0-9-]+$
You can try this.See demo.
http://regex101.com/r/oE6jJ1/16