With the following RegEx pattern:
(?<comment>(^#{2} [^\r\n]+[\s]+)*)(?:^\[(?:(?<hive>HK(?:LM|[DP]D|C[CUR]|U(SERS|SER|SR|S)))[:])?(?<name>[a-z0-9$][a-z0-9-_]{2,63})\])(?<items>[\S\s]*?)(?=\n{2,})
Parsing the following text:
[HKLM:Connection]
AuthKey = 0x8a79b42z67fct29b42e07b3fd78nc540
Url = https://dev.somewebsite.com
ApiPath = /api/
[HKLM:Settings]
AutoMinimizeConsole = no
StyleFile = Default
PhoneNbrs = [+]?[01]{0,3}[-. ]?[(]?[0-9][0-9][0-9][)]?[-. ]?[0-9][0-9][0-9][-. ]?[0-9][0-9][0-9][0-9]
PostalCodes = [ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy][0-9][ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvwxyz][\s.-]?[0-9][ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvwxyz][0-9]
[HKLM:Font-Mapping]
MonoSpaced = Courier New
User1 = Software Tester 7
User2 = Repetition Scrolling
User3 = basis333
[HKLM:UserInterface]
[HKCU:UserInterface]
[HKCU:Credentials]
Username =
Password? =
When entered into online Regex tests, the results come out as expected, but in code, no matches are found. The "data" variable used here is populated with the text provided above prior to this segment:
public const string GROUP_PATTERN = @"(?<comment>(^#{2} [^\r\n]+[\s]+)*)(?:^\[(?:(?<hive>HK(?:LM|[DP]D|C[CUR]|U(SERS|SER|SR|S)))[:])?(?<name>[a-z0-9$][a-z0-9-_]{2,63})\])(?<items>[\S\s]*?)(?=\n{2,})";
Regex groupParser = new Regex(GROUP_PATTERN, RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Multiline);
MatchCollection matches = groupParser.Matches(data);
foreach (Match m in matches)
this.Add(IniGroupItem.Parse(m.Value));
At the inception of the ForEach, there are zero matches (should be six!)..
Since the pattern works on test sites, but not at all in c#, I don't know how to figure out what issues the compiler is having with it. Any insights / suggestions?