How to construct a XPath using RegEx that ignores \r\n

Class library usage, coding and language questions.
User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

How to construct a XPath using RegEx that ignores \r\n

Post by Ciege » Tue Jun 21, 2011 10:41 pm

I am trying to figure a way to construct an xPath that will ignore any \r or \n in the path regardless of where they are and potentially treat them as whitespace. I'd like to first replace any \r\n with a space, then any \r with a space then any \n with a space. This way if it is \r\n it will be replace before i look for a single \r or a single \n alleviating the possibility of ending up with a double space.

For example, I have a column that the header is on 2 lines (i.e. First Line Second Line).The accessibleName of the cell according to Ranorex is "First LineSecond Line". I need to craft a RanoreXPath that can ignore the \r\n and treat is as a space. The reason being is I want my user to be able to call a method that looks for a cell by column name "First Line Second Line" and have the RegEx to be able to find that name ignoring the \r\n and converting it to a space as is *visible* to the user.

I can do this by getting each accessible names of each cell then running a .Replace on them but this is costly in that I have to read each cell first, then Replace on it, then compare... When in reality I should just be able to compare right from my FindSingle...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to construct a XPath using RegEx that ignores \r\n

Post by Ciege » Tue Jun 21, 2011 11:23 pm

OK, I figured it out... if I take the text that is passed in by the user and replace all " " (spaces) with "\s*" the RegEx will ignore all spaces including newline and carriage return.
Not quite what I wanted (a bit too greedy) but it works none the less...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...