Hi Everyone,
I have this Variable as the return of my query :
${query} = ((b’\x01’, ‘Morad’, datetime.datetime(2022, 4, 12, 15, 18, 57)),)
Can any one plz help me to extract the information from it using regex as bellow:
1
Morad
2022, 4, 12, 15, 18, 57
Regards
Hi Morad,
regex101 is a really useful site for playing with, learning and testing regex patterns
\\x(\d*)[^‘]*‘(\w*)[^\(]*\(([^\)]*)
follow this link to see how it works on regex101.com
Dave.
2 Likes
Hi Dave,
Thanks for your help.
i try to implement it but it doesn’t work in my code.
This is how i implement it :
${query} = DatabaseLibrary.Query SELECT FLAG,USER,DATE FROM record WHERE test = ‘63661446’
${result} = Get Regexp Matches ${query} \\x(\d*)[^‘]*‘(\w*)[^\(]*\(([^\)]*)
error: incomplete escape \x at position 0
Ho Morad,
In robot framework you need to escape the \'s:
${result} = Get Regexp Matches ${query} \\\\x(\\d*)[^‘]*‘(\\w*)[^\\(]*\(([^\\)]*)
In regex you also need to escape the \'s as well, so this is what’s often referred to as double escaping, your original string had \x01
to match the \x
part in regex we need to escape it as \\x
and then for the robot framework we also need to escape again so we get \\\\x
.
The \d
is a special regex command that means any digit, so we only need to escape it once for robot framework, it becomes \\d
, likewise for \w
. \(
and \)
are needed because (
and )
also need to be escaped because they have special meaning in regex they are the group identifier.
Hope that clears it up for you.
Dave.
Hi Dave,
Its totally clear.
The question is why it not working when i test it .
it Show me this error msg:
error: missing ), unterminated subpattern at position 25
The result seems to be a nested Python tuple (or a string representation of a such tuple). Instead of using regexps, I’d access items directly. If it’s a real tuple, you ought to be able to get all values like this:
${x} ${y} ${z} = Set Variable ${query}[0]
Notice also that b'\x01'
isn’t number 1 it’s byte 1.
1 Like