regex difficulty ?

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


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 = str )

m = str2 )

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