Regex Groups

Hi Everyone,
i have a text example:

* 19/11/21 SSS2/3000000 AAAA300007-0   028/2  782  4000      690,00    06
5527315
Dangerous goods:                                150,00
Additional performances:
- SUPPL.REDUCTION CH GOVERNMENT SUBSIDIES            5,00
- ADR SURCHARGE CH                                   2,00

19/11/21 BBB2/6000000 BBBB200006-0   222/2  715  2620      690,00    06
5545628
Additional performances:
- SUPPL.REDUCTION CH GOVERNMENT SUBSIDIES            150,00

Regex Code:
((?<DATE>(\d{1}|\d{2})\/(\d{1}|\d{2})\/\d{2})\s[A-Z0-9]{4}\/\d{7}(?<LE>\s[A-Z]{4}\d{6}\-\d).*(?<Preis>\s\d+,\d{2})\s+06(.|\n)*?(?<GGF>(?=(Dangerous goods:).\d+,\d{2})|)(.|\n)*?(?<SUB>(?=(SUBSIDIES)\s+\d+,\d{2})|)(.|\n)*?(?<ADR>(?=(ADR SURCHARGE CH)\s+\d+,\d{2})|).*)

But it does take all values what it should take. I can get values of group DATE, LE and Price but not others.

What am i missing?

Hi,

How about the following pattern?

 (?<DATE>\d{1,2}/\d{1,2}/\d{2})\s[A-Z0-9]{4}/\d{7}\s*(?<LE>[A-Z]{4}\d{6}-\d).*?(?<Preis>\s\d+,\d{2})\s+06[\s\S]*?Dangerous goods:\s*(?<GGF>\d+,\d{2})[\s\S]*?SUBSIDIES\s+(?<SUB>\d+,\d{2})[\s\S]*?ADR SURCHARGE CH\s*(?<ADR>\d+,\d{2})

Sequence5.xaml (7.6 KB)

Regards,

Hi,
Thanks, but that is not the required Solution. As you can see, dangerous goods and ADR may or may not be part of the data. So it must be handled also.

regex101: build, test, and debug regex (Regex tester)

Hi,

Alright. There are 2 records and “dangerous goods” and “ADR” does not always exist, right?
Can your try the following?

System.Text.RegularExpressions.Regex.Matches(yourString,"(?<DATE>\d{1,2}/\d{1,2}/\d{2})\s[A-Z0-9]{4}/\d{7}\s*(?<LE>[A-Z]{4}\d{6}-\d).*?(?<Preis>\s\d+,\d{2})\s+06[\s\S]*?(Dangerous goods:\s*(?<GGF>\d+,\d{2})[\s\S]*?)?SUBSIDIES\s+(?<SUB>\d+,\d{2})[\W]*(ADR SURCHARGE CH\s*(?<ADR>\d+,\d{2}))?")

Sequence5.xaml (8.4 KB)

Regards,

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