Regex Help for varying text and lines

Below is My Text and the lines varies like below and output should amount and tax value

Scenario1:
Organization: OU2510 EGDI Supplier Site: PORTLAND Invoice Number: 1706619 Tax Value: 215.47 Date: 19-MAY-2020
Amount: 1,372.90 AUD Invoice Received Date: 20-MAY-

Scenario 2:
Organization: OU2510 EGDI Supplier Site: PORTLAND Invoice Number: 1706619 Tax Value: 215.47 Date: 19-MAY-2020
Amount: 1372.90 AUD Invoice Received Date: 20-MAY-

Scenario 3:
Organization: OU2510 EGDI Supplier Site: PORTLAND Invoice Number: 1706619 Tax Value: 215.47 Date: 19-MAY-2020 Amount: 1,372.90 AUD Invoice Received Date: 20-MAY-

Scenario 4:
Organization: OU2510 EGDI Supplier Site: PORTLAND Invoice Number: 1706619
Tax Value: 215.47 Date: 19-MAY-2020
Amount: 1,372.90 AUD Invoice Received Date: 20-MAY-

Output:
215.47
1372.90

Hi,

Hope the following helps you.

Tax Value

System.Text.RegularExpressions.Regex.Match(text,"(?<=Tax Value:\s*)[.,\d]+").Value

Amount

System.Text.RegularExpressions.Regex.Match(text,"(?<=Amount:\s*)[.,\d]+").Value.Replace(",","")

Regards,

4 Likes

Hello

Try this Main.
Main.xaml (7.5 KB)

Regex Patterns:
(?<=Tax Value: )[\d.,]+
(?<=Amount: )[\d.,]+

Regex101.com Link - Tax Amount
Regex101.com Link - Amount

Cheers

Steve

2 Likes

To getTax value → Use Split function and Split with “Tax Value:” and store in String array variable
Then Take Split(1).Tostring.Trim and Assign in a String variable.
StringVariable.Split({" "},Stringsplitoptions.none) → Take in String Array variable
Then Split(0).Tostring will give result

For amount

Use Split function and Split with “Amount:” and store in String array variable
Then Take Split(1).Tostring.Trim and Assign in a String variable.
StringVariable.Split({" "},Stringsplitoptions.none) → Take in String Array variable
Then Split(0).Tostring will give result

@Yoichi @Steven_McKeering sometimes there is no space between Tax and Value it can TaxValue

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(text,"(?<=Tax\s*Value:\s*)[.,\d]+").Value

Regards,

Hello

Update the pattern to the following.
(?<=Value: )[\d.,]+
Regex101.com preview

it errored

Hello again

You could try this pattern:
(?<=Tax Value: )[\d.,]+|(?<=TaxValue: )[\d.,]+
It will work for either "Tax Value: " or "TaxValue: "

1 Like

this worked perfectly thanks Steve and yoichi for help

1 Like

Hi,

Do you use regex101? This site is not 100% compatible with .net regex.
Can you try on uipath actually or .net regex tester such as .NET Regex Tester - Regex Storm etc

Regards,

2 Likes

This is true and worth noting @vboddu.

@Yoichi’s solution would work fine also. I use Regex101.com out of habit (the sharing functionality). Its better to be using RegexStorm.Net

@Yoichi knows way more than me! :blush:

@vboddu - Please mark Yoichi’s post as a solution. Its simpler than my suggestion.
image

1 Like

@Yoichi thanks yoichi that worked. new stuff to remember

2 Likes

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