Page 1 of 1

Get Value Regex Question

Posted: Fri Apr 15, 2016 12:09 pm
by Fergal
I have a step to "Get Value", "Text" from a repository item. When the step is run without any regex it gets the value: $2,025.99

The value I want is: 2025.99, i.e. the number with decimal but without comma or Dollar sign.

On http://regexr.com/ the two regexs below return the value required, i.e. 2025.99
  1. (?:\d*\.)?\d+
  2. [^$,]
However, in Ranorex those regexs return the value: 2

What regex should I be using in Ranorex?

Why is it that a regex used on http://regexr.com/ returns a different value than the same regex used in Ranorex?

Thanks!

Re: Get Value Regex Question

Posted: Fri Apr 15, 2016 1:21 pm
by odklizec
Hi,

I would suggest to use different regex validator, namely one, which supports .NET regex engine. Like this one:
https://www.myregextester.com/index.php

As Kelly (krstcs) once pointed, most of online regex validation tools use javascript-based regex engine, which could deliver different results from the one used by Ranorex (.net based)!

BTW, in case you missed it, there is also a built-in regex toolkit directly in Ranorex! Check menu Tools >> Advanced Tools >> Regular Expressions Toolkit

As for your problem, the thing is that the regex does not return single string, but as I understand it, it rather returns a number of individual characters in array. And Ranorex probably picks the first element in array? So I think you would have to find a better regex?

Re: Get Value Regex Question

Posted: Tue Apr 19, 2016 4:46 pm
by Fergal
Thanks very much for all of that odklizec. I used "\d*\,?\d*\.\d*" and it worked for my needs, as it returns a number that can be parsed to a double. That regex link works very well, so thanks also for that.
odklizec wrote:...there is also a built-in regex toolkit directly in Ranorex! Check menu Tools >> Advanced Tools >> Regular Expressions Toolkit...
Has Ranorex published any details on how to use that?

Re: Get Value Regex Question

Posted: Tue Apr 19, 2016 5:21 pm
by krstcs
Not that I know of, but I think it's pretty self-explanatory. Play around with it and see what happens when you do different things.

You put the regex in the "Regex" field, the input text in the "Input" field, and hit "OK".

If you need to do replacements, click the "Replacement" checkbox and enter the replacement text in the "Replacement text" field.

For example:
Regex: '([0-9]*)' -> This is a regex group, it will only return the part inside the parenthesis
Input: 'Example123Text'
Result: 123 (String) 7 (Start) 10 (End) 3 (Length) 2 (Groups)

Clicking the row for that result will highlight the matching text in the input field.


If you're new to Regex or haven't used it much, I found this site to be really good at explaining it: http://www.regular-expressions.info/

Re: Get Value Regex Question

Posted: Wed Apr 20, 2016 11:04 am
by Fergal
Thanks for all of that krstcs, it is very helpful.

For anyone else new to Regular Expressions, they might also find the http://regexone.com/ site helpful.