Extract total cost from string by regex

Hi Everyone.

I have a string as below… I have used regex to extract the string as below picture.

But how to customize to received length of cost when it change.

Thanks in advance!

My Code: [cC][ộỘ][nN][gG] *[tT][iI][ềỀ][nN] *[hH][àÀ][nN][gG] *( *[tT][oO][tT][aA][lL]) :-(.)\d{1,2} *% *\d{1,3}[,.]\d{1,3}

Thanks in advance!

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=\(Total\):.*?%\D?)[.,\d]+",System.Text.RegularExpressions.RegexOptions.IgnoreCase).Value

If this doesn’t work, can you share original text as a file?

Regards,

1 Like

Hi Bro.

I have tried but not success.

I have two string

  • This is total cost for your site - Cộng tiền hàng (Total): 181.818 10% 18.182.123 . pls arrange to pay before deadline

  • This is total cost for your site - Cộng tiền hàng (Total): 1.718.213 10% 11.819.829 . pls arrange to pay before deadline

I want to extract 4 substring:

  1. Cộng tiền hàng (Total): 1.718.213 10% 11.819.829
  2. 1.718.213
  3. 10%
  4. 11.819.829

Thanks in advance!

Hi,

Can you try the following?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=^.*?-\s).*?:\s([.,\d]+)\s(\d+%)\s([.,\d]+)")

Main.xaml (7.1 KB)

Regards,

1 Like

Thanks you very much bro!

1 Like

Hi Bro.

Sorry, i have another small question.

How to count number of Group when regex string ?

Thánks in advance!

Thanks you.

I have known count the number of groups

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