[Mono-list] RegExp Bug ...

Piers Haken piersh@friskit.com
Wed, 4 Sep 2002 09:38:34 -0700


Mono bug aside...

"d*.y" matches any number of 'd's followed by any character followed by
y.

"d.*y" matches d followed by any number of any character followed by y.

But '*' is greedy, so in your example it would match "day Bloody Sunday"

May be you want "d.*?y"

I _believe_  perl works in the same way, in fact the .NET RegExs are
supposed to pretty close to the perl 5 ones.

Piers.

> -----Original Message-----
> From: Hans-Jürgen Schönig [mailto:mono@cybertec.at] 
> Sent: Wednesday, September 04, 2002 8:35 AM
> To: Mono-list@ximian.com; eg@cybertec.at
> Subject: [Mono-list] RegExp Bug ...
> 
> 
> I have found a bug in the regular expression implementation: 
> Here is what I am doing:
> 
> using System;
> using System.Text.RegularExpressions;
> 
> public class Demo
> {
> 	public static void Main()
> 	{
> 		string str = "Sunday Bloody Sunday";
> 
> 	        Regex reg = new Regex("d*.y");
> 		MatchCollection mat = reg.Matches(str);
> 		Console.WriteLine("Gefunden: " + mat.Count );
> 	        for     (int i = 0; i < mat.Count; i++)
>                 {
>                         Console.WriteLine("{0} - {1}", i, mat[i]);
>                 }
> 	}
> }
> 
> 
> and that comes out:
> 
> 
> [hs@duron regexp]$ mono file.exe
> Gefunden: 2
> 0 - day
> 1 - day
> 
> 
> and that comes out when running windows:
> 
> C:\monobsp>csc file.cs
> Microsoft (R) Visual C# .NET Compiler version 7.00.9466
> for Microsoft (R) .NET Framework version 1.0.3705
> Copyright (C) Microsoft Corporation 2001. All rights 
> reserved. C:\monobsp>file
> Gefunden: 3
> 0 - day
> 1 - dy
> 2 - day
> C:\monobsp>
> 
> 
> by the way: why is there no way to use d.*y to find 
> day,dy,day? d*.y looks VERY ugly to a Perl programmer ... 
> (thanks to Bill G.). Can anybody verify this and fill out a bugzilla?
> 
> 	Hans
> 
> 
> 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com 
> http://lists.ximian.com/mailman/listinfo/mono-> list
>