[IronPython] Regexp issue, or not :)

Sanghyeon Seo sanxiyn at gmail.com
Wed Apr 19 15:48:40 CEST 2006


2006/4/19, Albert Einstein <porkone at wp.pl>:
> m = re.compile("[a-z]+")
> p = m.match("sometext")
> p.group()
>
> Traceback (most recent call last):
> File , line 0, in input##44
> File , line 0, in group##15
> IndexError: Index was outside the bounds of the array.
>
> Is it bug in IronPython?

Yes it is. The documentation says:
http://docs.python.org/lib/match-objects.html

group([group1, ...])
Without arguments, group1 defaults to zero (the whole match is returned).

Here's a simple fix:

--- IronPython/Modules/re.cs.orig       2006-04-19 22:28:31.000000000 +0900
+++ IronPython/Modules/re.cs    2006-04-19 22:28:42.000000000 +0900
@@ -518,6 +518,11 @@
             }

             [PythonName("group")]
+            public object group() {
+                return m.Groups[0].Value;
+            }
+
+            [PythonName("group")]
             public object group(object index) {
                 return m.Groups[GetGroupIndex(index)].Value;
             }

Seo Sanghyeon



More information about the Ironpython-users mailing list