如何在多个分组中获取两个匹配

huangapple go评论56阅读模式
英文:

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.+)");

huangapple
  • 本文由 发表于 2023年5月18日 05:48:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76276420.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定