Return Innertext using Regex

Best practices, code snippets for common functionality, examples, and guidelines.
theraviz
Posts: 72
Joined: Sun Apr 14, 2019 9:46 am

Return Innertext using Regex

Post by theraviz » Tue Jul 14, 2020 10:34 am

Hi,

I need to get the inner text of an element having numbers and alhpabets as numbers only.

Is there a way to apply regular expression in the Xpath and then return the Innertext only with Numbers?

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

Re: Return Innertext using Regex

Post by odklizec » Tue Jul 14, 2020 5:35 pm

Hi,

Sure, there is always a way to achieve what you want. Just please post a Ranorex snapshot (not screenshot) of the problematic element. And don’t forget to specify, what exactly you want to get from given element. Thanks.
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

theraviz
Posts: 72
Joined: Sun Apr 14, 2019 9:46 am

Re: Return Innertext using Regex

Post by theraviz » Wed Jul 15, 2020 8:24 am

odklizec wrote:
Tue Jul 14, 2020 5:35 pm
Hi,

Sure, there is always a way to achieve what you want. Just please post a Ranorex snapshot (not screenshot) of the problematic element. And don’t forget to specify, what exactly you want to get from given element. Thanks.
Hi,

Thank you for the reply. I have attached the ranorex snapshot of the element (which is a TD). Here the innertext of the TD is 28.5067 USD.
I want to add this element to the repository and get the innertext as 28.5067 only by removing the USD.

Thanks in advance
Attachments
Regex.rxsnp
(1018.63 KiB) Downloaded 4 times

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

Re: Return Innertext using Regex

Post by odklizec » Wed Jul 15, 2020 11:09 am

Hi,

I’m not behind my PC, but give a try regex from this post...
https://www.ranorex.com/forum/issues-wi ... tml#p57377
Just replace GB with USD. Hope this helps? 😉
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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12143
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Return Innertext using Regex

Post by Support Team » Wed Jul 15, 2020 2:24 pm

Here is another option:

Code: Select all

\d+.\d+
https://regex101.com/r/hxZtdj/1

In English, this matches: (Any number of digits).(Any number of digits)
\d = Any single digit
+ = Match 1 or more digits

Cheers,
Ned
.
Image

theraviz
Posts: 72
Joined: Sun Apr 14, 2019 9:46 am

Re: Return Innertext using Regex

Post by theraviz » Thu Jul 16, 2020 11:06 am

Thank you @Support Team, @Odklizec. It worked :)