开发者

c# regex to search text but not report it in the matched groups

开发者 https://www.devze.com 2023-04-01 05:39 出处:网络
I have the following output from a utility I use for data processing. Processed output from W765 build 66721

I have the following output from a utility I use for data processing.

Processed output from W765 build 66721
File target: C:\Documents and Settings\Jon\Desktop\test\1024\cards.dat
Cards loaded: 876 1456 1457 1459 2072
Errors encountered (0)
Warnings encountered (0)
Pass

I want a .Net regex to be able to retrieve as groups just 876 1456 1457 1459 2072 and nothing else.

I have got to this that works

([0-9]\d+)+

but unfortunately it yields

Found 8 matches:

765
66721
1024
876
1456
1457
1459
2072

I thought this would work instead

.开发者_开发问答*(?:Cards loaded\: )([0-9]\d+)+

but it doesn't.

Can someone please point me in the right direction.

Thank you Jonathan Bolton


Try with this:

Cards loaded:(?'digits'(\d|\s)+)

this will return in the named group "digits" the numeric portion you need


Maybe you could try Cards loaded\: [\d\s]+ to return Cards loaded: 876 1456 1457 1459 2072, then on that string, do \d+ to get each of the relevant results.


Use this:

(?m)(?<=^Cards loaded: (?:\d+\s)*)\d+

Output:

c# regex to search text but not report it in the matched groups


Does it have to just be a regex, i.e. just remove the guff you don't want from the begining before parsing

string toSearch = @"Processed output from W765 build 66721 File target: C:\Documents and Settings\Jon\Desktop\test\1024\cards.dat Cards loaded: 876 1456 1457 1459 2072 Errors encountered (0) Warnings encountered (0) Pass";
string shortened = toSearch.Substring(toSearch.IndexOf("Cards loaded:"));
var matches = Regex.Matches(shortened,@"([0-9]\d+)+");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号