IBM Support

When to use double backslash to escape special character in regular expression

Question & Answer


Question

When do you need to use double backslash to escape special character in regular expression using IBM® Rational® Robot?

Answer

When a string is double quoted, it is processed by the compiler and again at run-time. Since a backslash (\) is removed whenever the string is processed, the double-quoted string needs double backslashes so that there is one left in the string at run time to escape a "special character".

For Example:
We would like to extract ICRow0 using from a response where the pattern is as below:




    /*
    NAME=SEARCH_RESULT1 HREF=\"jav"
    "ascript: submitAction_main1(document.main1,'#ICRow0')\" TABINDEX=28>10<"
    "/A></TD>\n"
    */
The regular expression to be used in the match statement would be:

    "NAME=SEARCH_RESULT1 HREF=\"javascript: submitAction_main1\\(document.main1,'#([A-Za-z0-9]*)$0'\\)\" TABINDEX=28", sTemp3,&sRow);

where the right parenthesis and left parenthesis are the special characters that need to be escaped.

Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

.

[{"Product":{"code":"SSSHDX","label":"Rational Robot"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Playback","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2003.06.00;2003.06.10;2003.06.12;2003.06.13;2003.06.14;2003.06.15;2003.06.16;7.0;7.0.0.1;7.0.0.2;7.0.0.3;7.0.1;7.0.1.1;7.0.1.2;7.0.0.4;7.0.1.3;7.0.2","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

133182735

Document Information

Modified date:
16 June 2018

UID

swg21152248