Regex101 icon indicating copy to clipboard operation
Regex101 copied to clipboard

Support for non-raw strings as a delimiter option (doubly-escaped symbols)

Open seojumper opened this issue 6 months ago • 2 comments

Feature

We use the site for helping to build out regex patterns for Robot Framework which provides a number of keywords for using regex patterns in tests. These keywords require regex patterns provided to keywords be "double escaped" as a lone '\' char will cause the script to fail to be parsed correctly by the Robot runtime.

From Robot's documentation https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Regular%20expressions

Regular expressions

Some keywords, for example Should Match Regexp, support regular expressions that are more powerful but also more complicated that glob patterns. The regular expression support is implemented using Python's re module and its documentation should be consulted for more information about the syntax. Because the backslash character (\) is an escape character in Robot Framework test data, possible backslash characters in regular expressions need to be escaped with another backslash like \\d\\w+. Strings that may contain special characters but should be handled as literal strings, can be escaped with the Regexp Escape keyword.

Inside of a robot script file an example usage of one of such keywords must look like this where you see the pattern must have double escaped symbols or will not be parsed correctly.

${interface_status}=    Get Regexp Matches
...    ${interface_output}
...    (\\S+)\\sis (up|down|administratively down), line protocol is (up|down)

Since we are needing to work "in code" with "doubly escaped" symbols in patterns, it would be handy if the site could offer a non-raw delimiter option for its python engine that understands doubly-escaped symbols.

Currently when writing these files (as a number of folks enjoy using the site to aid in creating/tshooting the patterns they write) we are taking a doubly-escaped pattern from Robot script > copying it over to the site > manually removing double escapes so the site can understand it > fixing the pattern with the help of the site > copying the fixed pattern back into robot and manually re-inserting the double escape sequences where needed which is a very error prone process, and also a friction point when you need to make multiple iterations on a pattern.

Would be nice if support for this could be reconsidered as it would certainly make the site that much easier to use for our (and other Robot users) use case.

seojumper avatar Feb 06 '24 18:02 seojumper

Hello @seojumper,

Here's some potentially helpful things in the meantime: Replace \\ with \

To get the escaped stuff, select javascript as the code generator syntax. No flags, but it seems they're limited and can be set inline as per the linked documentation.

working-name avatar Feb 06 '24 19:02 working-name

That is a handy workaround/workflow that I'll add to our teams docs. Thank you.

seojumper avatar Feb 06 '24 20:02 seojumper