Regex two lines

Total Charges / Activities:
Miscellaneous Charges … 100,123.40

Hi, I am trying to get the amount from the above using RegEx
(?<=Total Charges\s/\sActivities:\s*.\s)[\d+,.]+

But it is also giving me the dotted line. Can you help please?

Hi @A_Learner

Try this

\d+,\d+\.\d+

image

Hi @A_Learner

Try this (Modified regex expression):

System.Text.RegularExpressions.Regex.Matches(strinput,"(?<=Total Charges\s\/\sActivities:\n*.|\s)[\d,.]+")

Or use this regex expression:

System.Text.RegularExpressions.Regex.Matches(strinput,"[\d].*")

Datatype: IEnumerable(System.Text.RegularExpressions.Match)

Hope it helps!!

HI,

Can you try to add (?=\r?\n|$) as the following?

(?<=Total Charges\s/\sActivities:\s*.*\s*)[\d+,.]+(?=\r?\n|$)

image

Regards,

1 Like

Thank you. Need a generic one amount can vary like for example 123.45 and also 123,456,789.01?

Regards,

Thank you, @Yoichi
It works great!!
Why do I need to have $ at the end?

Thanks a lot,

Hi @A_Learner

You can use the data manipulations to extract the output data

- Assign -> strvar = "Total Charges / Activities:
                      Miscellaneous Charges … 100,123.40"
- Assign -> output = strvar.Split("…")(1).Trim.ToString

Check the below workflow for your reference

Hope it helps!!

Hi,

Because if there is numeric character before the target, it will be matched. To prevent it, it’s necessary to set pattern the target exists at the end of the line or string (\r?\n|$).

Regards,

1 Like

Thank you, @Yoichi for explaining.

Thank you @mkankatala

Thank you @A_Learner

Happy Automation!!!

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