I use load runner 12.5 to record script . I want to extract a value in response script and pass it to other so I want to find 17821107849674 in script with regular expression. what should I do?
.
.
.
AdfLoopbackUtils.runLoopback(
9,
'_afrLoop',
'17821107849674',
'_afrWindowMode',
'Adf-Window-Id',
'_afrPage',
'',
'w0',
';EBOXPORTALID=3fUCuSHtu2lAMvjhIqj5GMCRNrUTXZ_E0w-nQGzQxolJ4T38oItW!-939378123',
'!',
false,
Loadrunner should be using PCRE as the default regex engine.
So you could look for 14 digits surrounded by word boundaries \b:
\b(\d{14})\b
Or more precisely, look for 14 digits and lookaround for single quotes :
(?<=\')(\d{14})(?=\')
To be even more precise and check if it's followed by that _afrWindowMode:
((?<=\')[0-9]+(?=\',\s*\'_afrWindowMode\'))
Tell us more about the pattern? Is it always the third element in the set? Is it always preceded by "'_afrLoop'," or followed by ",'_afrWindowMode'?"
You potentially have several paths to collect the value, but understanding the patterns involved helps
Related
I want to match the first 1 to 3 characters of set [A-Z], but I want to ignore the prefix XYZ_.
Example:
XYZ_ABC1234
XYZ_DEF1234
DEF0000A0
D00A0
BCDA1
CDE
I'm trying to use a negative lookahead of the form ^(?!XYZ_)?[A-Z]{1,3}. However, this will return 'XYZ' from the first two examples (works fine for the other examples). I.e. its output is:
XYZ_ABC1234
XYZ_DEF1234
DEF0000A0
D00A0
BCDA1
CDE
How can I ignore a prefix (if it exists) from a string and match on the condition I'm looking for after it?
It turns out this is somewhat Python specific to the re module.
I was able to achieve my desired outcome using \K which resets the starting point of the reported match.
As such, if using the Perl Compatible Regex Expression (PCRE), the answer is: ^(?:XYZ_\K)?[A-Z]{1,3}
More can be read here
I tried to match number 13 in pipe separated string like the one below:
13 - match
1|2|13 - match
13|1|2 - match
1|13|2 - match
1345|1|2 - should fail
1|1345|2 - should fail
1|2|1345 - should fail
1|4513|2 - should fail
4513|1|2 - should fail
2|3|4|4513- should fail
So, if 13 only occurs at the beginning or end, or in-between the string as a whole word it should match.
For that I wrote the following regex:
^13$|(\|13\|)?(?(1)|(^13\||\|13$))
In Regex101 it is working as expected. Please click link to see my sample.
But in Postgresql it throws error for the following query:
SELECT * FROM tbl_privilage WHERE user_id = 24 and show_id ~ '^13$|(\|13\|)?(?(1)|(^13\||\|13$))';
Error:
ERROR: invalid regular expression: quantifier operand invalid
SQL state: 2201B
Don't use a regex, using an array is more robust (and maybe more efficient as well):
select *
from the_table
where '13' = any (string_to_array(the_column, '|'));
this assumes that there is no whitespace between the values and the delimiter. You can even index that expression which probably makes searching a lot faster.
But I agree with Frank: you should really fix your data model.
Documentation is quite clear, saying that operator ~ implements the POSIX regular expressions. In Regex101 you're using PCRE (Perl-compatible) regular expressions. The two are very different.
If you need PCRE regular expressions in PostgreSQL you can setup an extension. Like pgpcre.
You need to match 13 within word boundaries.
You need
[[:<:]]13[[:>:]]
This solution should work even if you have spaces around the numeric values.
See documentation:
There are two special cases of bracket expressions: the bracket
expressions [[:<:]] and [[:>:]] are constraints, matching empty
strings at the beginning and end of a word respectively.
I need to filter a set of strings with a wildcard-type search, like the following:
Looking for He*lo should match "Hello", but not "Helo"
Looking for *ant should match "pant" and "want" but not "ant"
Looking for *yp* should match "gypsy" and "typical"
The * represents one or more characters. I don't mind a handwritten or regex-based search. Any ideas? The typical .NET approach for wildcards matches 0 or more, but I need 1 or more characters. How can I do this?
What you're looking for is the + regex operator
You want the .
For example: he.lo will match your hello, but not helo.
same goes for the rest.
You can easily test it here: http://regexpal.com/.
Do note that .yp. will not match typical nor gypsy, but `.yp.+' will (because of the rest of the characters)
For a Google Analytics funnel I want to write a regEx that will match the URLs with the following pti ids:
1, 5, 8, 13, 14, 49, 79
For example, these are valid URLs
/OrderProcess/OrderConfirmation.aspx?pti=1
/OrderProcess/OrderConfirmation.aspx?pti=1|16
/OrderProcess/OrderConfirmation.aspx?pti=48|1|47
/OrderProcess/OrderConfirmation.aspx?pti=5|7|11
but these are not:
/OrderProcess/OrderConfirmation.aspx?pti=16
/OrderProcess/OrderConfirmation.aspx?pti=2|16|51
This regex matches URLs that start with the number but don't match numbers after the pipes:
.*OrderConfirmation.*pti=(1|5|8|13|14|49|79).*
There are nearly 100 ids and they could appear in the variable in any order. Is it possible?
You need the "word boundary" regex \b:
.*OrderConfirmation.*pti=.*\b(1|5|8|13|14|49|79)\b.*
Using the word boundary means id 1 doesn't match |17|.
See a live demo on rubular of various edge cases.
You need to escape the pipes, since they are reserved symbols in Regular Expressions:
.*OrderConfirmation.*pti=(1|1\|16)
Will match /OrderProcess/OrderConfirmation.aspx?pti=1 and /OrderProcess/OrderConfirmation.aspx?pti=1|16.
(Adding the rest should be easy from here on.)
Note that if you write this:
.*OrderConfirmation.*pti=(1|1\|16).*
Then the expression will match .*OrderConfirmation.*pti=1 or .*OrderConfirmation.*pti=1|16` followed by anything. If you want to allow other parameters (that aren't always there), you need this:
.*OrderConfirmation.*pti=(1|1\|16)($|&.*)
Which means that the first expression can either be followed by the end of string or & which can in turn be followed by anything.
The regular expression which I have provided will select the string 72719.
Regular expression:
(?<=bdfg34f;\d{4};)\d{0,9}
Text sample:
vfhnsirf;5234;72159;2;668912;28032009;4;
bdfg34f;8467;72719;7;6637912;05072009;7;
b5g342sirf;234;72119;4;774582;20102009;3;
How can I rewrite the expression to select that string even when the number 8467; is changed to 84677; or 846777; ? Is it possible?
First, when asking a regex question, you should always specify which language you are using.
Assuming that the language you are using does not support variable length lookbehind (and most don't), here is a solution which will work. Your original expression uses a fixed-length lookbehind to match the pattern preceding the value you want. But now this preceding text may be of variable length so you can't use a look behind. This is no problem. Simply match the preceding text normally and capture the portion that you want to keep in a capture group. Here is a tested PHP code snippet which grabs all values from a string, capturing each value into capture group $1:
$re = '/^bdfg34f;\d{4,};(\d{0,9})/m';
if (preg_match_all($re, $text, $matches)) {
$values = $matches[1];
}
The changes are:
Removed the lookbehind group.
Added a start of line anchor and set multi-line mode.
Changed the \d{4} "exactly four" to \d{4,} "four or more".
Added a capture group for the desired value.
Here's how I usually describe "fields" in a regex:
[^;]+;[^;]+;([^;]+);
This means "stuff that isn't semi-colon, followed by a semicolon", which describes each field. Do that twice. Then the third time, select it.
You may have to tweak the syntax for whatever language you are doing this regex in.
Also, if this is just a data file on disk and you are using GNU tools, there's a much easier way to do this:
cat file | cut -d";" -f 3
to match the first number with a minimum of 4 digits
(?<=bdfg34f;\d{4,};)\d{0,9}
and to match the first number with 1 or more length
(?<=bdfg34f;\d+;)\d{0,9}
or to match the first number only if the length is between 4 and 6
(?<=bdfg34f;\d{4,6};)\d{0,9}
This is a simple text parsing problem that probably doesn't mandate the use of regular expressions.
You could take the input line by line and split on ';', i.e. (in php, I have no idea what you're doing)
foreach (explode("\n", $string) as $line) {
$bits = explode(";", $line);
echo $bits[3]; // third column
}
If this is indeed in a file and you happen to be using PHP, using fgetcsv would be much better though.
Anyway, context is missing, but the bottom line is I don't think you should be using regular expressions for this.