This is my token cookie based extractor used into my jmeter:
I'm receiving:
However, I'm sending "NOT FOUND":
Any ideas?
As per Meta Characters chapter of JMeter Regular Expressions User Manual entry:
Regular expressions use certain characters as meta characters - these characters have a special meaning to the RE engine. Such characters must be escaped by preceding them with \ (backslash) in order to treat them as ordinary characters. Here is a list of the meta characters and their meaning (please check the ORO documentation if in doubt).
( and )
grouping
[ and ]
character classes
{ and }
repetition
*, , + and ?
repetition
.
wild-card character
\
escape character
|
alternatives
^ and $
start and end of string or line
So you need to escape this + with the backslash like:
Set-Cookie: id_token=Bearer\+(.+?);
However be aware that you can use HTTP Cookie Manager in order to get the cookie value:
Add the next line to user.properties file:
CookieManager.save.cookies=true
Restart JMeter to pick the property up
That's it, now you can refer the cookie value as ${COOKIE__id_token} where required.
Related
Hi I have a file which has a string in it that is in an array format and i'm using jq to loop through each index and have some logic depends on the string on each index. However there is a backslash character and jq returns invalid escape character. So I think I need to escape the backlash. How can I do that using sed?
Example:
["*","*Cases","*/opt/selenium/tests/src/test/cases","*../../src/test/cases","*01 Login","*/opt/selenium/tests/src/test/cases/01_login.robot","*../../src/test/cases/01_login.robot","*TC001 Verify the login","*<p>If member has clicked 'Remember Me' check box, after the deployment, it's not necessary to input account and password when login. Web do not have the 'Remember Me' function\x3c/p>","*Login button is not visible after 60 seconds"]
You wrote you want to escape any backslash (\), not slash (/). Assuming that the escape character is backslash itself, then the following should do the job:
sed -i 's/\\/\\\\/g' filename
This can become even shorter:
sed -i 's/\\/&&/g' filename
but using literals in the replacement instead of the variable & is more efficient.
In case you just made a kind of typo, and you want instead to escape slashes with backslashes, then the following command should suffice:
sed -i 's|/|\\/|g' filename
(Since I used | instead of /, I don't need to escape the / in the replacement.)
You can escape / with \/ in sed like this:
sed -i "s#\/#\\\/#g" filename
The error is probably caused by the escape sequence \x3c appearing in one of the string literals.
That is a valid escape sequence in JavaScript (it represents the character <), but in JSON it is invalid.
JSON does support Unicode escapes, though: \u003c.
Apparently you got your input from some kind of JavaScript serializer.
The best solution would of course be to replace that by a proper JSON serializer.
If that is not possible or not practical (for example because it comes from a third party),
then you could use sed to replace every \xnn with its Unicode counterpart \u00nn.
sed 's/\\x\([0-9A-Fa-f]\{2\}\)/\\u00\1/g' poorjson.txt
Output:
["*","*Cases","*/opt/selenium/tests/src/test/cases","*../../src/test/cases","*01 Login","*/opt/selenium/tests/src/test/cases/01_login.robot","*../../src/test/cases/01_login.robot","*TC001 Verify the login","*<p>If member has clicked 'Remember Me' check box, after the deployment, it's not necessary to input account and password when login. Web do not have the 'Remember Me' function\u003c/p>","*Login button is not visible after 60 seconds"]
Please note that this is not 100% foolproof.
It does not check if the backslash itself has not been escaped.
I'm trying to load a csv that contains the character "|" without success
can i escape it or use other techinieue?
can you help?
thanks
If you are using '|' as your delimiter and some fields also contain '|', you can escape them as '\|'. (Or with some other character, if you've changed your escape character. But by default, '\'.)
If you have a lot of these, it might be easier to change your delimiter character. It doesn't have to be '|'. For example, you can do this:
=> COPY t1 FROM '/data/*.csv' DELIMITER '+';
You can use any ASCII value in the range E'\000' to E'\177', inclusive. See the documentation for COPY parameters.
This is related to cleaning files before parsing them elsewhere, namely, malformed/ugly CSV. I see plenty of examples for removing/matching all characters between certain strings/characters/delimiters, but I cannot find any for specific strings. Example portion of line would look something like:
","Should now be allowed by rule above "Server - Access" added by Rich"\r
To be clear, this is not the entire line, but the entire line is enclosed in quotes and separated by "," and ends in ^M (Windows newline/carriage return).The 'columns' preceding this would be enclosed at each side by ",". I would probably use this too to remove cruft that appears earlier in the line.
What I am trying to get to is the removal of all double quotes between "," and "\r ("Server - Access" - these ones) without removing the delimiters. Alternatively, I may just find and replace them with \" to delimit them for the Ruby CSV library. So far I have this:
(?<=",").*?(?="\\r)
Which basically matches everything between the delimiters. If I replace .*? with anything, be that a letter, double quotes etc, I get zero matches. What am I doing wrong?
Note: This should be Ruby compatible please.
If I understand you correctly, you can use negative lookahead and lookbehind:
text = '","Should now be allowed by rule above "Server - Access" added by Rich"\r'
puts text.gsub(/(?<!,)"(?![,\\r])/, '\"')
# ","Should now be allowed by rule above \"Server - Access\" added by Rich"\r
Of course, this won't work if the values themselves can contain comas and new lines...
I am trying to make a regular expression, that allow to create string with the small and big letters + numbers - a-zA-z0-9 and also with the chars: .-_
How do I make such a regex?
The following regex should be what you are looking for (explanation below):
\A[-\w.]*\z
The following character class should match only the characters that you want to allow:
[-a-zA-z0-9_.]
You could shorten this to the following since \w is equivalent to [a-zA-z0-9_]:
[-\w.]
Note that to include a literal - in your character class, it needs to be first character because otherwise it will be interpreted as a range (for example [a-d] is equivalent to [abcd]). The other option is to escape it with a backslash.
Normally . means any character except newlines, and you would need to escape it to match a literal period, but this isn't necessary inside of character classes.
The \A and \z are anchors to the beginning and end of the string, otherwise you would match strings that contain any of the allowed characters, instead of strings that contain only the allowed characters.
The * means zero or more characters, if you want it to require one or more characters change the * to a +.
/\A[\w\-\.]+\z/
\w means alphanumeric (case-insensitive) and "_"
\- means dash
\. means period
\A means beginning (even "stronger" than ^)
\z means end (even "stronger" than $)
for example:
>> 'a-zA-z0-9._' =~ /\A[\w\-\.]+\z/
=> 0 # this means a match
UPDATED thanks phrogz for improvement
I want regular expression for checking whether a word has . or / like abcd. or abcd/a or abcd.def or abcd/def. Any help will be gr8!
/[\/\.]/
Usage
if "some test. string" =~ /[\/\.]/
# ..
end
Both / and . are reserved characters in regex, so you would normally need to escape them. The exception to this is that . doesn't need to be escaped when it's in a character class, which is how you'd want to search in this case.
The escape chararacter in regex is \, so your / character becomes \/. Your . remains as it is.
Therfore, to check if a string contains either a / or a ., you would need a regex that looks something like this:
/[.\/]/
This will check any string and return true if it contains either of these characters anywhere within the string, regardless of what else is in the string.
/(\.|\/)/ matches the period or slash to a group.
/[\/\.]/ just matches for period, slash or both.