Get Value Regex Question

Ask general questions here.
Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Get Value Regex Question

Post by Fergal » Fri Apr 15, 2016 12:09 pm

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!

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

Re: Get Value Regex Question

Post by odklizec » Fri Apr 15, 2016 1:21 pm

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?
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

Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Get Value Regex Question

Post by Fergal » Tue Apr 19, 2016 4:46 pm

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?

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Get Value Regex Question

Post by krstcs » Tue Apr 19, 2016 5:21 pm

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/
Shortcuts usually aren't...

Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Get Value Regex Question

Post by Fergal » Wed Apr 20, 2016 11:04 am

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.