AttributeRegEx with variable

Ranorex Studio, Spy, Recorder, and Driver.
Posts: 122
Joined: Fri Aug 05, 2011 7:52 am

AttributeRegEx with variable

Post by swmatisa » Fri Nov 14, 2014 7:30 am

Win7 SP1 64 bits
Ranorex 5.2.0

I cannot use a variable in a regex for validation with AttributeRegEx.
Regex1.jpg (127.91 KiB) Viewed 2516 times
The result:
Regex2.jpg (173.49 KiB) Viewed 2516 times
I have a workaround (topic 4), but it is harder for my real test

Any idea?

(20.14 KiB) Downloaded 138 times

User avatar
Ranorex Guru
Ranorex Guru
Posts: 7425
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: AttributeRegEx with variable

Post by odklizec » Fri Nov 14, 2014 9:24 am


I may be wrong, but it seems it's not possible to combine the variable and regex in Recording validation, using the AttributeRegEx option? There are two workarounds, both require the use of User Code action.

First, convert your AttributeRegEx action to user code, right click the converted step and select View Code. this should move you to just converted code. Then simply change the new Regex("(?i:'+$Var2+')") to new Regex("(?i:"+Var2+")"). This should do the trick ;)

Another option is to add the regex directly to variable, via a User Code step placed before the validation step. Then just validate the variable.
Example of user code:

Code: Select all

        public void SetVar()        	
        	Var2 = "(?i:"+Var2+")";
Hope this helps?
(20.71 KiB) Downloaded 181 times
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Posts: 122
Joined: Fri Aug 05, 2011 7:52 am

Re: AttributeRegEx with variable

Post by swmatisa » Tue Nov 18, 2014 7:42 am

Hello odklizec,

Thanks for your suggestions. As I write in my first post I also have another workaround with the Regex in the repository.

It is strange (not orthogonal) to have the possibility to use a variable and Regex in the repository and not with Validate (AttributeRegEx) :(