Hello:

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
Vigo-Spain


using System;
using System.Text.RegularExpressions;

namespace RegexTest
{       
        public class Test 
        {
                [STAThread]
                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 = @"(('[^'[EMAIL 
PROTECTED]']*')*[^'@]*?)*(?<param>@\w+)*([^'@]*?('[^'[EMAIL PROTECTED]']*'))*";

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

                        MatchEvaluator me = new MatchEvaluator(matchEvaluator);

                        sql = r.Replace(sql, me);

                        Console.WriteLine(sql);
                }

                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");
                        }
                        else
                        {
                                return match.Value;
                        }
                }
        }
}

Reply via email to