First, I wanted to thank you for creating this! I needed an INI reading/writing solution for C# and this gave me a great starting point. Your C# file is quite robust. Much appreciated!
Your regular expression's logic works fine, but all subpattern names mus be unique to prevent pattern errors. I'm not sure if this causes issues for the way your c# code works, but it will cause issues if this is ever expanded to include additional subpatterrn matches in the same function where you're trying to identify them by name.
Here's the updated regular expression to get around this issue:
(?=\S)(?<text>(?<comment>(?<open_comment>[#;]+)(?:[^\S\r\n]*)(?<value>.+))|(?<section>(?<open_section>\[)(?:\s*)(?<value_section>[^\]]*\S+)(?:[^\S\r\n]*)(?<close>\]))|(?<entry>(?<key>[^=\r\n\ [\]]*\S)(?:[^\S\r\n]*)(?<delimiter>:|=)(?:[^\S\r\n]*)(?<value_entry>[^#;\r\n]*))|(?<undefined>.+))(?<=\S)|(?<linebreaker>\r\n|\n)|(?<whitespace>[^\S\r\n]+)
And here it is in regex101: https://regex101.com/r/x37Qua/1
First, I wanted to thank you for creating this! I needed an INI reading/writing solution for C# and this gave me a great starting point. Your C# file is quite robust. Much appreciated!
Your regular expression's logic works fine, but all subpattern names mus be unique to prevent pattern errors. I'm not sure if this causes issues for the way your c# code works, but it will cause issues if this is ever expanded to include additional subpatterrn matches in the same function where you're trying to identify them by name.
Here's the updated regular expression to get around this issue:
(?=\S)(?<text>(?<comment>(?<open_comment>[#;]+)(?:[^\S\r\n]*)(?<value>.+))|(?<section>(?<open_section>\[)(?:\s*)(?<value_section>[^\]]*\S+)(?:[^\S\r\n]*)(?<close>\]))|(?<entry>(?<key>[^=\r\n\ [\]]*\S)(?:[^\S\r\n]*)(?<delimiter>:|=)(?:[^\S\r\n]*)(?<value_entry>[^#;\r\n]*))|(?<undefined>.+))(?<=\S)|(?<linebreaker>\r\n|\n)|(?<whitespace>[^\S\r\n]+)And here it is in regex101: https://regex101.com/r/x37Qua/1