Regular expression escaping in configuration file [message #1768347] |
Mon, 17 July 2017 17:40 |
|
I'm using Eclipse Titan 6.2.0 and am currently playing with the
TELNETasp TestPort. This port requires the user to specify the prompt
on the telnet server for use with "buffered" mode. This works fine for
a fixed prompt situation. For variable prompts (such as those that
change with context of where you are in the navigation of a MIB), one
can specify regular expressions, e.g. using "REGEX_PROMPTn" variables.
However, as soon as want to use the '\' escaping character to include
symbols like () or # in the prompt, the Titan test executor complains:
Parse error in configuration file `sysinfo/Test.cfg': in line 15, at or before token `\$': Invalid escape
sequence in string literal.
Can somebody explain to me what is the correct method to escape in
regex's spcified in the config file?
|
|
|
Re: Regular expression escaping in configuration file [message #1768462 is a reply to message #1768347] |
Wed, 19 July 2017 06:42 |
|
Hi Harald,
Please try to double-escape (e.g. as in '\\$') the symbols in question;
Here's why: there are at least two parsers that will interpret your string:
the config file parser and the regexp parser of the TELNET port, each with a different mission and set of rules.
Some special characters ( "^", "$", "\", """ etc.) can be interpreted literally or as a control character and interpretation may be different from layer to layer.
For instance the first parser may recognize the special character \n as "newline" and send it as 0xd to the next parser ;
but it may not recognize \$ (it's not a C-style escape) and it may send it to the next parser as literal \ followed by literal $
However if you escape "\" (as in "\\$") this will force interpretation of "\$" as "end of line" regex and the first parser will send "\$" (as control character) to the next parser.
(This is a theoretical example, I did not check the Titan code, but this is a typical scenario on the web, making thousands of hacks possible :) )
I hope this makes sense
Please let me know if it works
Best regards
Elemer
[Updated on: Wed, 19 July 2017 09:06] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03066 seconds