[Mono-list] Regular expression question

Carlos Guzmán Álvarez carlosga@telefonica.net
Sat, 12 Jun 2004 16:19:50 +0200

This is a multi-part message in MIME format.
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit


Atatched is a sample test case using regular expressions
that fails in mono (Fedora Core 1) but works fine in .NET.

The problem seems to be in the:

return Regex.Replace(input, g.Value, "$1");

it can be fixed using:

return Regex.Replace(input, g.Value, "$$1");

But as the code works fine in .NET using a single $ i want to
know if it's a mono problem or the double $$ is tyhe correct syntax ??

( For now i will fix my code it using $$ :) )

Best regards

Carlos Guzmán Álvarez

Content-Type: text/plain;
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;

using System;
using System.Text.RegularExpressions;

namespace RegexTest
	public class Test 
		public static void Main(string[] args)
			string sql = "insert into public.test_table values(@int4_field, @char_field, @varchar_field, @single_field, @double_field, @date_Field, @time_field, @timestamp_field, @blob_field)";

			string pattern = @"(('[^']*?\@[^']*')*[^'@]*?)*(?<param>@\w+)*([^'@]*?('[^']*?\@*[^']*'))*";

			Regex r = new Regex(pattern, RegexOptions.ExplicitCapture|RegexOptions.Multiline);

			MatchEvaluator me = new MatchEvaluator(matchEvaluator);

			sql = r.Replace(sql, me);


		public static string matchEvaluator(Match match)
			string input	= match.Value;
			string replace	= String.Empty;

			if (match.Groups["param"].Success)
				Group g = match.Groups["param"];
				return Regex.Replace(input, g.Value, "$$1");
				return match.Value;