I think the best way to ask this question is to provide an example.
I have a string:
string line = "12345";
string pattern = "[0-9]{4}";
MatchCollection collection = Regex.Matches(line, pattern);
This will return ONE match in the collection: "1234". BUT, is there a way to get it to return "1234" AND "2345"? So I want the regular expression to not skip characters that have been already been matched.
I'm very new to regular expressions so any h开发者_Go百科elp would be greatly appreciated. Thank you.
"(?=(\d{4}))" will not only match both substrings, they'll tell you so; you can access the values of the matched substrings using Match.Groups[1] for each match.
Change the expression to:
(?=\d{4})
精彩评论