Troubleshooting
Problem
A string contains a literal character that is a reserved character in the Regex class (for example, the '(' or open parentheses character). Placing a '\' (backslash) in front of the character in the regular expression generates an 'Invalid escape sequence' compilation error. This only occurs when the regular expression is used in the text of the script. The backslash character can be used as an escape sequence in a regular expression in a recognition property or a verification point.
Resolving The Problem
Instead of using the backslash as an escape sequence, specify the literal character by placing it in square brackets, for example, use
- Regex r = new Regex("[(]HelloWorld[)]");
instead of
- Regex r = new Regex("\(HelloWorld\)");
which generates the Invalid escape sequence error.
To re-iterate, the backslash character can be used as an escape sequence for a regular expression in a recognition property or a verification point. The compilation error only occurs when creating a regular expression in the script text.
Was this topic helpful?
Document Information
More support for:
Rational XDE Tester
Software version:
2003, 2003.06.00, 2003.06.01, 2003.06.12, 2003.06.13
Operating system(s):
Windows
Document number:
81601
Modified date:
16 June 2018
UID
swg21194641