Reputation: 45
I have data in the following format
name | height | hex assigned
[alphanumeric and spaces] | [numeric] cm| [hex]:[hex]
20 char | 5 char | 1 char: 1 char
What I'm trying to do is, to match the regexp
${escaped}= Regexp Escape '[A-Za-z0-9_\s] | [0-9]+ cm| [0-9a-f]:[0-9a-f]'
Should Match Regexp ${text} ${escaped}
Although the text is correct, the test keep failing.
Would really appreciate if someone could point out what I did wrong.
Upvotes: 1
Views: 15942
Reputation: 13640
You can use the following:
^[A-Za-z0-9_\s]{1,20}\s+\|\s+[0-9]{5} cm\|\s+[0-9a-f]:[0-9a-f]$
See DEMO
Upvotes: 2
Reputation: 386010
If you escape your regular expression, you're essentially converting the expression into a fixed string. You also have the problem that your pattern begins and ends with a single quote. Since robot treats the whole cell as the expression, your expression will only match if it actually begins and ends with a single quote.
The solution requires a few changes in what you're doing:
^
and $
) unless you want to match the pattern anywhere in the string\
is special in robot files, so to get a backslash in the pattern you must include two when defining the patternI think the following does what you want:
*** Variables ***
${pattern} ^[A-Z0-9_\\s]{1,20} \\| [0-9]+ cm\\| [0-9A-Fa-f]:[0-9A-Fa-f]$
*** Test cases ***
Example
Should Match Regexp 12345678901234567890 | 1 cm| 3:5 ${pattern}
Upvotes: 3