regex difficulty ?

Robert Nikander nikander at mindspring.com
Wed Nov 14 17:28:35 CET 2001


Hi,

I am trying to write a program that scans the GTK headers.  I am getting
confused about the following regular expression, and was hoping someone
could help explain...

Here is some simplified code that illustrates my problem.  I am trying to
match a prototype and extract the return type... the problem is I am
matching against the second one, when I don't think my regex says that...

str = 'char *  gtksomething'
str2 = 'extern "C"  { } gtksomething'

regex = re.compile(r'([\w\s*]*?)gtk')

m = regex.search( str )
print m.group(0)
print m.group(1)

m = regex.search( str2 )
print m.group(0)
print m.group(1)


On my system that second one matchs... ? Output is:

char *  gtk
char *
extern "C"  { } gtk
extern "C"  { }

How the heck is the [\w\s*] class matching the chars { } and "



More information about the Python-list mailing list