{"id":345,"date":"2009-12-06T14:36:19","date_gmt":"2009-12-06T12:36:19","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=345"},"modified":"2016-09-08T23:01:03","modified_gmt":"2016-09-08T21:01:03","slug":"regex-bug-on-mono","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/regex-bug-on-mono","title":{"rendered":"Regex bug on Mono"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2009\/12\/mono.png\" alt=\"mono\" title=\"mono\" width=\"83\" height=\"100\" class=\"alignleft size-full wp-image-347\" \/>This is a good advice for all creating applications using .NET that need to work on both Microsoft .NET and Mono.<\/p>\n<p>It seems that Mono ignores group indexes specified explicitly.<br \/>\nHere&#8217;s the code to reproduce this problem. <\/p>\n<p>The results on Mono are incorrect.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nRegex parser = new Regex(&quot;(?&lt;2&gt;.*?),(?&lt;1&gt;.*?),&quot;);\r\nMatch match = parser.Match(&quot;first,second,&quot;);\r\nConsole.WriteLine(&quot;Groups&#x5B;1].Value={0}&quot;, match.Groups&#x5B;1].Value);\r\nConsole.WriteLine(&quot;Groups&#x5B;2].Value={0}&quot;, match.Groups&#x5B;2].Value);\r\n<\/pre>\n<p>MS implementation:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nC:\\1\\ConsoleApplication\\1\\bin\\Debug&gt;ConsoleApplication1.exe\r\nGroups&#x5B;1].Value=second\r\nGroups&#x5B;2].Value=first\r\n<\/pre>\n<p>Mono 2.4.2.3 implementation:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nC:\\1\\ConsoleApplication\\1\\bin\\Debug&gt;mono.exe ConsoleApplication1.exe\r\nGroups&#x5B;1].Value=first\r\nGroups&#x5B;2].Value=second\r\n<\/pre>\n<p>The workaround is simple use names instead of numbers:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nRegex parser = new Regex(&quot;(?&lt;first&gt;.*?),(?&lt;second&gt;.*?),&quot;);\r\nMatch match = parser.Match(&quot;first,second,&quot;);\r\nConsole.WriteLine(&quot;Groups&#x5B;first].Value={0}&quot;, match.Groups&#x5B;&quot;first&quot;].Value);\r\nConsole.WriteLine(&quot;Groups&#x5B;second].Value={0}&quot;, match.Groups&#x5B;&quot;second&quot;].Value);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a good advice for all creating applications using .NET that need to work on both Microsoft .NET and Mono. It seems that Mono ignores group indexes specified explicitly. Here&#8217;s the code to reproduce this problem. The results on Mono are incorrect. Regex parser = new Regex(&quot;(?&lt;2&gt;.*?),(?&lt;1&gt;.*?),&quot;); Match match = parser.Match(&quot;first,second,&quot;); Console.WriteLine(&quot;Groups&#x5B;1].Value={0}&quot;, match.Groups&#x5B;1].Value); Console.WriteLine(&quot;Groups&#x5B;2].Value={0}&quot;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[35],"class_list":["post-345","post","type-post","status-publish","format-standard","hentry","category-programming","tag-mono"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/345"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=345"}],"version-history":[{"count":3,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":5042,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/345\/revisions\/5042"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}