Jmeter - Regex Extractor not working - regex

I'm trying to extract a simple string from the HTML response.
The response looks like this
patients-list-of-visits.aspx?p=a1363839-76fb-43f3-97ba-26218faefee1
The Regex I have tried so far are
patients-list-of-visits.aspx?p=(.+?)
patients-list-of-visits.aspx?p=(.+)
Can someone please let me know what am I doing wrong here?
Thanks!

This is better:
patients-list-of-visits\.aspx\?p=(.+)
2 remarks
don't forget to escape . and ? if you want to match them literally
your first attempt .*? is a lazy match and will result in in only the first letter being matched. Your second attempt is better

Related

Regex to find combination of lines not containing a string

I'm trying to find the correct regex that, within this input:
#Tag-1234
Scenario:
Blabla
Scenario:
Blabla
#Tag-1234
Scenario:
Blabla
Will select only the second one (the one without a tag).
So far I tried something like (?!#Tag-\d{4})\nScenario, but it's not doing the trick.
Can anyone throw some light into this?
I'm doing my tests on regex101 -> https://regex101.com/r/msDHKf/1
Thanks
It seems I was missing the \n before the tag that would concatenate to the search, so the regex would be
\n(?!#Tag-\d{4})\nScenario
So close!
In the pattern (?!#Tag-\d{4})\nScenario the lookahead can be removed as it is directly followed by matching \nScenario so the assertion will always be true.
If there should be no tag before Scenario but a newline, you can just match 2 newlines and then Scenario
\n\nScenario\b
See a regex demo.

Regex to remove a whole phrase from the match

I am trying to remove a whole phrase from my regex(PCRE) matches
if given the following strings
test:test2:test3:test4:test5:1.0.department
test:test2:test3:test4:test5:1.0.foo.0.bar
user.0.display
"test:test2:test3:test4:test5:1.0".division
I want to write regex that will return:
.department
.foo.0.bar
user.0.display
.division
Now I thought a good way to do this would be to match everything and then remove test:test2:test3:test4:test5:1.0 and "test:test2:test3:test4:test5:1.0" but I am struggling to do this
I tried the following
\b(?!(test:test2:test3:test4:test5:1\.0)|("test:test2:test3:test4:test5:1\.0"))\b.*
but this seems to just remove the first tests from each and thats all. Could anyone help on where I am going wrong or a better approach maybe?
I suggest searching for the following pattern:
"?test:test2:test3:test4:test5:1\.0"?
and replacing with an empty string. See the regex demo and the regex graph:
The quotation marks on both ends are made optional with a ? (1 or 0 times) quantifier.

Regex inverse match for the whole line

I've been trying to get this to work for an hour now but can't seem to do it, neither with the help of SO articles, or Regex101.com.
Have have some data and would like to return the lines that does not contain "/Common/http". Example data:
/Common/http and /Common/Another
/Common/http-mymon
/Common/another /Common/http
another line
The result I am looking for is:
/Common/http-mymon
another line
Any regex I use must match the whole line or it fails in the engine I use (https://github.com/jayway/JsonPath). This means that http would not work, but .*http.* would.
Hope this is fairly clear?
/Patrik
You can use a negative lookahead regex like this:
^(?:.*?/Common/http-mymon|(?!.*/Common/http)).*$
RegEx Demo
Update:
As per comment below OP wants to exclude /Common/http followed by / or a whitespace. In that case try this regex:
^(?!.*/Common/http(?:/|\s)).*$
RegEx Demo 2
I think you can go with the following regex
^(?!.*\/Common\/http(?:\s))(.*?)$
This one is checking for no /Common/http in front before space using negative lookahead (?!.*\/Common\/http(?:\s))

Simple regex replaces more than it should in a string

I'm trying to create a regular expression that replaces an URL with a token. That's how far I got, and I don't understand why this expression replace everything after the URL as well except for the last word.
string<-"This is a website http://www.bla.com that I like very much"
gsub("https?://.*\\s|www.*\\s"," [url] ",string)
>>"this is a website [url] much"
Appreciate your help very much!
The problem is the .* - it will match anything greedily, so you will match all the way up to the last space. try
gsub("https?://[^[:blank:]]*","[url]",string) instead.

What is wrong with this really really simple RegEx expression?

this one is really easy.
I'm trying to create a Regular Expression that will result in a Successful Match when against the following text
/default.aspx?
So i tried the following...
^/default.aspx$
and it's failing to match it.
Can someone help, please?
(i'm guessing i'm screwing up becuase of the \ and the ? in the input expression).
The problem is in the .(dot), which is a wildcard,
You must escape it like \..
Also, Because there is a ? at the end of URL and $ (end-of-input) is in the regexp, therefore, it does not match.
The correct regexp should be ^/default\.aspx(\?.*)?$
The $ at the end of ^/default.aspx$ means 'match the end of the string', but the string you're searching ends with '?'.
Maybe something like this is more appropriate:
^/default\.aspx(\?.*)?$
This will match default.aspx, with an optional ?whatever-else-that-comes-after.