Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Parsing a Long Decimal Number from a String Using Reg-Ex

Tommy_Alterax
8 - Asteroid

HI Guys,

 

I am looking to Parse a long decimal number from a String using REGEX.

 

File attached below however, sample string looks like this 

 

"<SpotWholesale xmlns="RateCompositionInfo"><Value>0.91409999999999991</Value><State>Defaulted</State><CalculationMethod xsi:nil="true"/></SpotWholesale> 

 

The piece I want parsed is after first <Value> , the only number in the string. So I can identify this number  easily in Regex however, parsing the full decimal number is troublesome. It is rounding the number and giving me a whole number

 

Not all instances will there be a "0" before the decimal point 

I want the full number extracted - HELP !

 

 

4 REPLIES 4
Felipe_Ribeir0
16 - Nebula

Hi @Tommy_Alterax 

 

Why dont you use the xml parse instead of regex?

Felipe_Ribeir0_0-1674817032644.png

 

Tommy_Alterax
8 - Asteroid

Thats amazing Felipe thank you. I had used XML earlier in my workflow but didn't realise I could parse further.

 

I am trying to improve my REGEX understanding, any ideas how this could be solved in REGEX ? - Juts for my own curiosity

 

Felipe_Ribeir0
16 - Nebula

Hi @Tommy_Alterax 

 

Yes, there are multiple ways. Here is one of them:

REGEX_Replace([Value], '(.*<Value>)(.*)(<\/Value>.*)', '$2')

 

Basically, it means that we have a first group (.*<Value>), that has a any character + <Value>

Then, we have a second group of any characters (the group that we want)

And there is a third group (<\/Value>.*) that has <\/Value> + any character

And we want the second group  = '$2'

 

String

anything<Value>    0.91409999999999991     </Value>anything

       group 1               |          group 2                               |         group 3

 

Felipe_Ribeir0_0-1674817723352.png

 

Tommy_Alterax
8 - Asteroid

Thanks for this comprehensive answer Felipe

Labels
Top Solution Authors