Getting text before first and second occurrence

Hi all

I have this text - Kitchen Cooke New World FL 15.8 KW/h Yes N/A N/A Yes N/A High: High: Yes No Yes Yes r - / New Low: Low: Gas home MJ175GO L Utility Boiler Ideal / RS 11.6 KW/h Yes N/A N/A Yes Pass High:0.000 High:0.000 Yes No Yes Yes Room - Gas Logic + 5 5 Under Heat 18 Low:0.000 Low:0.000 70kw 7 7 - how would I get the text before KW/h, both the first occurrence of it (15.8) and the second (11.6)? The text before will always be different and be different lengths but as far as I’m aware, the digits will always be in the format xx.x ?

Thanks :slight_smile:

Hey @Short

We can use Regex to obtain each value :slight_smile: Take a look here for a preview.

I have created a sample workflow for you to download and review.
Main.xaml (6.0 KB)
Output pane from workflow:
image

The Regex pattern I created will match both instances of 15.8 and 11.6.
15.8 will be match 1.
11.6 will be match 2.

I then used assigned the result to a new string variable for each result.

As long as there are only ever two values in your input text then this will work.

If you want to learn Regex, then take a look here at my Regex Megapost.

Hopefully this helps :blush:

1 Like

Hi @Steven_McKeering

You’re a life saver, thank you! I will definitely be learning Regex, I’ve been meaning to for a while but it seems a lot to get my head around

Thanks again :slight_smile:

1 Like

You are in the right place for Regex help - the UiPath Community forums :blush: there are lots of people who can help.

Keep it simple when learning Regex. Ask for help with the hard stuff :wink:

I don’t know everything but reach out if ever need help or want to fact check your regex understanding :slight_smile:

1 Like

Hi again @Steven_McKeering

Thanks again for all of your help, but of course I came across a match in the format of 11 KW/h which the regex doesn’t catch as there’s no decimal point. I have tried to amend it :joy: but it was an absolute disaster. Are you able to help please so it can recognise the formats of both 11.3 KW/h and 11 KW/h?

Thanks :blush:

Hey

Try this pattern.

It doesn’t need the decimal point :slight_smile:

Is it likely to go over 999?

1 Like

I was trying everything but didn’t think of that! Thank you so much again!

No I don’t think so, it should always be in double digits :slight_smile:

1 Like

It will still work 9999999 KW/h.

But not 1,000 KW/h.

Happy Automation! :blush:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.