0

In code generated by Ranorex I have seen that spaces are escaped when text comparison is done on Regex basis:

table[@controlid='1008']/?/?/cell[@text~'^This\ text\ has\ spaces']

I wondered about that, because in "normal" (all kinds of different Regex I've seen until now), the space is not a special character.

Googling about it I found the Ranorex XPath site which has the example

listitem[@text~'^sample\ 123$'] matches 'sample 123' (use backslash to escape special characters like space)

Following the examples, there is a list of special characters, as there are

.
$
|
*
+
?
^
()
[]
[^0-9]

It further refers to Microsoft .NET Regex (MSDN), which sounds reasonable, since Ranorex tests are developed on .NET basis with SharpDevelop.

Being a C# develop for 10 years, I'm pretty sure that a space is not a special character in .NET Regex.

What is special about a space in a Ranorex Regex?

0

There is nothing special about it and spaces do not need to be escaped. It's more likely that Ranorex uses Regex.Escape(), which escapes the spaces (emphasis mine):

Escapes a minimal set of characters (\, *, +, ?, |, {, [, (,), ^, $,., #, and white space) by replacing them with their escape codes.

The following code demonstrates this:

using System;
using System.Text.RegularExpressions;

public class Program
{
    public static void Main()
    {
        Console.WriteLine(Regex.Escape("This text has spaces"));
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.