regex parse multiple expressions - regex

I have a requirement to parse part of url with multiple expressions using regex, expressions are like /abc/def (or) /z/a (or) /v/g. I have a regex that satisfies single expression, but not sure how to do for multiple expression.
(?<volga>.+?\/abc\/def.+?)
volga is a named capturing group.
Above regular expression satisfies anything before /abc and anything after /def, the same way url also has /z/a and /v/g. This is kind of either /abc/def/ or /z/a or /v/g can exist in url. How to write a regular expression that checks for all of above expressions.
Examples of url:
/api/com/abc/def/710660716/847170/
/api/com/z/a/

Maybe this:
(?<volga>.+?\/((abc\/def)|(z\/a)|(v\/g)).*)
Matches any string containing
abc/def
or z/a
or v/g
Regex101

Related

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

In JMeter I need to extract a specific Regular Expression

In the following String:
Events('1234', '123456', '', 'QW233Cdse');
I need to extract "QW233Cdse"
Any suggestion?
When we are working with regular expressions then its very important that we should look for the static text in the test string that can help to create a strong regular expression.
As in your case, "Events()" seems to be a static text containing dynamic value in the round parenthesis so in order to generate the regular expression you need to keep 'Events()' text and add the expression in the round parenthesis as mentioned below:
Test String: Events('1234', '123456', '', 'QW233Cdse');
Regular Expression can be:
Events(.'(.)');
Events(.* '(.+?)');
Note: The backslash before round parentheses would avoid interpreting the round braces as unescaped character. For example, a parenthesis "(" begins the definition of a quantifier, but the leading backslash of parenthesis "(" indicates that the regular expression should match the parenthesis.
Regular expression is most important item to learn when you are working with load testing tools and you can refer to below blog post to get more information on regular expression:
https://www.redline13.com/blog/2016/01/jmeter-extract-and-re-use-as-variable/
Let me know if you have any further question
The relevant regular expression would be something like:
Events\(.* '(.+?)'\);
Demo:
References:
JMeter: Regular Expressions
Using Regular Expressions in JMeter
Perl 5 Regex Cheat sheet
Try using this regex:
\w+(?='\))
Regex would be:
, '([^']+?)');
Configuration would be:

Regular Expression to unmatch a particular string

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.

Multiple max lengths in a regular expression

I have the following regular expression:
[0-9]{7}-[0-9]{1}$
I should be able to match the following patterns:
1234567-8
3142539-1
But not the following:
12345678-1
1234567-12
Currently my regex matches 12345678-1 but not 1234567-12 (in JavaScript). Both should fail. What am I doing wrong?
Your pattern would match any string that ends($) with [0-9]{7}-[0-9]{1} and so it would match those inputs..
Use ^(start of the string) to specify that you want to match exactly..
^[0-9]{7}-[0-9]{1}$

regular expression content-type

I am using asp.net madam in my application and I want to check switch to basic authentication based on content-type requested. But only way to add discriminator is through regular expression and I am very poor in regular expressions, Can anyone help me write a regular expression which checks whether string is either "application/json" or "application/xml" in regular expression.
There is a simple regular expression to match it:
^application/(json|xml)$
If you don't have clear that the string is at the beginning and end of the line, just:
application/(json|xml)
And if you need to escape the / bar:
application\/(json|xml)
You may even need not to capture the json|xml expression, so you can do:
application\/(?:json|xml)