Regex 101 Exercise I10 - Extract repeating hex blocks from a string
Posted on 2006-03-08 00:36 Sheva 阅读(669) 评论(2) 编辑 收藏 举报Regex 101 Exercise I10 - Extract repeating hex blocks from a string
Given the string:PCORR:BLOCK=V5CCH,IA=H'22EF&H'2354&H'4BD4&H'4C4B&H'4D52&H'4DC9;
Extract all the hex numbers in the form “H’xxxx”
----------------------------------------------------------------------------------------------
Answer:
Regex regex = new Regex(@"(?<HexBlocks>H'[A-F_0-9]{4})", RegexOptions.IgnoreCase);
String inputString = @"PCORR:BLOCK=V5CCH,IA=H'22EF&H'2354&H'4BD4&H'4C4B&H'4D52&H'4DC9;";
MatchCollection matches = regex.Matches(inputString);
foreach (Match match in matches)
{
Console.Write("{0} ", match.Value);
}
String inputString = @"PCORR:BLOCK=V5CCH,IA=H'22EF&H'2354&H'4BD4&H'4C4B&H'4D52&H'4DC9;";
MatchCollection matches = regex.Matches(inputString);
foreach (Match match in matches)
{
Console.Write("{0} ", match.Value);
}