How to provide regex for the text file

Hi,
Im attaching a text file I need to get the values below extra charges using regex. How to provide that.
Can any one please explain.
I need to get these two values

~Gas-Delivery Service~$~20.57
~Packing-charges~$~5.20

Sample_Text.txt (335 Bytes)

@Chippy_Kolot

Please try this regex

(?<=Gas-Delivery Service~\$~).*

For the next replace gas delivery service with the packing charges

Read the text fie into str then

System.Text.RegularExpressions.Regex.Match(str,"(?<=Gas-Delivery Service~\$~).*").Value

Cheers

Hi, In my use case I need to extract
~Gas-Delivery Service~$~20.57 and ~Packing-Charges~$~5.20, not only amount.
I need those two line item

@Chippy_Kolot

Remove the lessthan symbol you will get whole

Cheers

Hi,
Can you try this one:

@Chippy_Kolot

Try this

(?<=Extra Charges:).*(?=~SUB-TOTAL)

System.Text.RegularExpressions.Regex.Match(str,"(?<=Extra Charges:).*(?=~SUB-TOTAL)",RegexOptions.SingleLine).Value.Trim

Cheers

Hi @Chippy_Kolot,

If you want a more dynamic approach to capture the extra charges (which is possible if a user has purchased extra items besides gas delivery and packing charges), might as well capture anything in between the “Extra Charges:” and “SUB-TOTAL” strings. Here’s the regex pattern:

To access this in a UiPath variable, you can use assign activity with the following values:

Assign: VariableName = System.Text.RegularExpressions.Regex.Match(ValueFromTextFile,“~Extra Charges:\n(?s)(.*)~SUB-TOTAL”).Groups(1).Value

You can clean this string by removing empty lines and using .Trim string functions. Up to you.

Cheers.

Hi @Chippy_Kolot

Try this one-

“~\w+~$\d+.\d+”

Thanks!!

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