Help with a regex

I have this text:
-62953:31 HOUR
24-MAR-2005 23:59 UTC

I need to check the number before HOUR.

It can also be this:
17114 CYCLES
N/A

Then I need to extract the number before the word CYCLES
Can anyone help with the regex for this.
Thanks

Hey @chauhan.rachita30
try use this:
matchResult = System.Text.RegularExpressions.Regex.Match(inputString, “(-?\d+)\s*(HOUR|CYCLES)”)
then you can use if activity:
If matchResult.Success Then
extractedValue = matchResult.Groups(1).Value

Hello

Another option- preview the pattern here:
System.Text.RegularExpressions.Regex.Match(inputString, “\d+(?=\s(HOUR|CYCLES))”)
image

Also if you need the full time you could use this pattern
image

Cheers

Steve

Hi @chauhan.rachita30

Assign-> Input = "-62953:31 HOUR
         24-MAR-2005 23:59 UTC"

Assign-> Output = System.Text.RegularExpressions.Regex.Match(Input,"\d+\s*(?=HOUR|CYCLES)").Value.Trim()
Assign-> Input = "17114 CYCLES"

Assign-> Output = System.Text.RegularExpressions.Regex.Match(Input,"\d+\s*(?=HOUR|CYCLES)").Value.Trim()

Let me know if you have any other queries.
Regards

Hi,
I need the whole negative number. -62953
Thanks

Hello

Try this pattern - preview it here:
[-\d]+(?=:[\d\s]*HOUR)|\d+(?=\sCYCLES)

Hi @chauhan.rachita30

Use this then:
\-?\d.*\s*(?=HOUR|CYCLES)

Hope you understand and if you have any queries let me know @chauhan.rachita30
Regards

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