如何将下划线视为空格提取文档编号

问题描述 投票:0回答:0

发票词有时由下划线字符 (_) 分隔或代替空格:

...
Reg nr_11687767_KMKR_EE101308591
Invoice Nr.
M230714_some text
Kirjeldus
...

有时会被换行终止

...
Reg nr_11687767_KMKR_EE101308591
Invoice Nr.
M230714
01.05.2023
Kirjeldus
...

或其他空白分隔符:

...
Reg nr_11687767_KMKR_EE101308591
Invoice Nr M230714   Date 01.05.2023
Kirjeldus
...

尝试使用 RegEx 提取数字

  Regex.Match(tekst, @"(?si).*_?ARVE[\s_]?NR[\s_:\.]?(?<arvenumber>.*?)[\s_]");

成功是真的但是arvenumber组是空的

如何在arvenumber群中只获得号码M230714?

使用 C# ASP.NET 7

c# regex pattern-matching match matching
© www.soinside.com 2019 - 2024. All rights reserved.