英文:
How to get two matches on multiple groups
问题
Invoice total section contains text
Sum without 20% _48,15
Vat 20% _9,63
Invoice total (EUR)_57,78
Tried to get Vat text and VAT sum using nested group kmtekst
var tekst=@"Sum without 20% _48,15
Vat 20% _9,63
Invoice total (EUR)_57,78
";
var rida = Regex.Match(tekst, @"(?si).*(?<kmtekst>Vat(_)?(\s)?(20%)?(:))?(\s)?(_)?(?<kmaks>[\d,\.]*)(\s)?.*");
rida.Success is true but
but
rida.Groups["kmaks"].Value
and
rida.Groups["kmtekst"].Value
are empty. How to get
9,63
as rida.Groups["kmaks"].Value
and
Vat 20%
as rida.Groups["kmtekst"].Value
?
Using .NET 7 ASP.NET MVC controller Regex
英文:
Invoice total section contains text
Sum without 20% _48,15
Vat 20% _9,63
Invoice total (EUR)_57,78
Tried to get Vat text and VAT sum using nested group kmtekst
var tekst=@"Sum without 20% _48,15
Vat 20% _9,63
Invoice total (EUR)_57,78
";
var rida = Regex.Match(tekst, @"(?si).*(?<kmtekst>Vat(_)?(\s)?(20%)?(:))?(\s)?(_)?(?<kmaks>[\d,\.]*)(\s)?.*");
rida.Success is true but
but
rida.Groups["kmaks"].Value
and
rida.Groups["kmtekst"].Value
are empty. How get
9,63
as rida.Groups["kmaks"].Value
and
Vat 20%
as rida.Groups["kmtekst"].Value
?
Using .NET 7 ASP.NET MVC controller Rexgep
答案1
得分: -1
尝试以下。
var rida = Regex.Match(tekst, @"(?<kmtekst>Vat.+%).+?(?<kmaks>\d.+)");
英文:
Try the following.
var rida = Regex.Match(tekst, @"(?<kmtekst>Vat.+%).+?(?<kmaks>\d.+)");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论