Regular Expression to unmatch a particular string - regex

I am trying to use regular expression in Jmeter where in I need to unmatch a particular string. Here is my input test string : <activationCode>insvn</activationCode>
I need to extract the code insvn from it. I tried using the expression :
[^/<activationCode>]\w+, but does not yield the required code. I am a newbie to regular expression and i need help with this.

Can you use look-behind assertion in jmeter? If so, you can use thatr regex which will give you a word that follows <activationCode>
(?<=\<activationCode\>)\w+
If your input string is encoded (e.g for HTML), use:
(?<=\<activationCode\>)\w+

When designing a regular expression in any language for something like this you can match your input string as three groups: (the opening tag, the content, and the closing tag) then select the content from the second group.

Related

Jmeter correlation for values with no left or right boundries

I wanna correlate a alphanumeric 81fe8bfe87576c3ecb22426f8e57847382917acf value returned from a POST API request as Response which consists of no left or right boundaries, I am using ^[a-zA-Z0-9]+$ as regex expression which is a correct regex expression with Jmeter RegExp Tester, but unable to extract the alphanumeric value from the response and store in a variable as determined by the logs using Regular Expression Extractor.
But, Values returned by the logs shows unable to extract alphanumeric value using Regular Expression Extractor.
Here is my Regular Expression Extractor to extract the alphanumeric value
I already have tried out all the Fields to check options available, nothing works. I am not sure , exactly why is it not working as the regex expression ^[a-zA-Z0-9]+$ is correct, maybe it's related to empty or no left and right boundaries.
Would really appreciate any resolution provided.
Your ^[a-zA-Z0-9]+$ regex contains no capturing groups, but your template, $1$, retrieves Group 1 value from the match. Since the match has no Group 1, the value is not found.
There are two solutions:
Replace your ^[a-zA-Z0-9]+$ with ^([a-zA-Z0-9]+)$ and keep on using $1$ template.
Replace $1$ with $0$ so as to access the whole match value, Group 0, rather than Group 1 (that is missing in the original regex).
You need to surround your regular expression with parentheses in order to have a capture group, see Meta Characters chapter of JMeter User Manual for more information
Given you need to extract only alphanumeric characters you can simplify your regular expression to just (\w+)
Given you need to get the full response you can just use Boundary Extractor and leave both boundaries blank - JMeter will store the whole response into a JMeter Variable (it will work for JMeter 5.2 or higher, see JMeter Bug 63775 for details
If you need to store the whole response into a JMeter Variable and want to use Regular Expression Extractor for this the relevant regular expression would be (?s)(^.*)

Regular Expression Pattern which should not allow ,;:|

I need the regular expression pattern which should not allow to put any of following characters into input in HTML
,;:|
You may get some idea from this.
[^,;:|]+
DEMO::: https://rubular.com/r/dKQzC1HrnMG88X

Regular Expression - Starting and ending with, and contains specific string in the middle

I would like to generate a regex with the following condition:
The string "EVENT" is contained within a xml tag called "SHEM-HAKOVETZ".
For example, the following string should be a match:
<SHEM-HAKOVETZ>104000514813450EVENTS0001dfd0.DAT</SHEM-HAKOVETZ>
I think you want something like this ^<SHEM-HAKOVETZ>.*EVENT.*<\/SHEM-HAKOVETZ>$
Regular expression
^<SHEM-HAKOVETZ>.*EVENTS.*<\/SHEM-HAKOVETZ>$
Parts of the regular expression
^ From the beginning of the line
<SHEM-HAKOVETZ> Starting tag
.* Any character - zero or more
EVENT Middle part
<\/SHEM-HAKOVETZ>$ Ending part of the match
Here is the working regex.
If you want to match this line, you could use this regex:
<SHEM-HAKOVETZ>*EVENTS.*(?=<\/SHEM-HAKOVETZ>)
However, I would not recommend using regex XML-based data, because there may be problems with whitespace handling in XML (see this article for more information). I would suggest using an actual XML parser (and then applying the reg to be sure about your results.
Here is a solution to only match the "value" part ignoring the XML tags:
(?<=<SHEM-HAKOVETZ>)(?:.*EVENTS.*)(?=<\/SHEM-HAKOVETZ>)
You can check it out in action at: https://regex101.com/r/4XiRch/1
It works with Lookbehind and Lookahead to make sure it will only match if the tags are correct, but for further coding will only match the content.

Finding a pattern with optional end using regular expression

I am looking for one single regular expression to extract a block of text, which can be surrounded with an optional end. The challenge here is just to use a single regular expression.
The input is as follows:
Anchor: This is the text I want to extract A/C : 2015-5-20
Anchor: This is the text I want to extract
I am currently using the following regular expression
Anchor:(?<extact>.*)(A\/C)
The result looks as follows:
If I make the A/C block optional, Anchor:(?<extact>.*)(A\/C)? using a ? the matching gets to long:
It looks as follows:
Any ideas how to elegantly solve this with a single regex. An additional constraint is that I want to have a named block in the regex, (here extact)
You can find the sample code on regex101: https://regex101.com/r/wH5iQ4/1
Anchor:(?<extact>.*?)\s*(?=A\/C|$)
You can make use of lookahead here.See demo.
https://regex101.com/r/wH5iQ4/3

mongodb regular expressions matching

i am having these kind of strings
"abc?ref1=app";
"abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx"
where xxxxxxxxxxxxxxx is some string...
i want to write regular expression which should only match "abc?ref1=app" types of strings and should not match any other string like "abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx" ..i mean it should only and only match "abc?ref1=app" type of strings...
i have written some thing like this /abc\?ref1=app/ ..but this will also match "abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx"
please tell me how to write regular expression which will only match "abc\?ref1=app"
You do not even need regex here, since mongoDB uses lexographical comparison
a simple
{ "myStr" : { $lte : "abc?ref1=app" }
where myStr is your db key
will work
a string like abc?ref1=app&xyz would be counted as greater than your query.
Add an end-of-line ($) token
abc\?ref1=app$