Python RE Query.

Robert Gahan gahanr at gofree.indigo.ie
Sat Sep 15 09:08:34 EDT 2001


Hi all,

I am trying to use Python RE to return the arguements associated with a
C function signature. Trying to "group" each parameter arguement by use of
parenthesis.

It does not seem to be working for me !!.
Can anyone give me a hand ??.

Thans again,
Rob.

import re

# I am trying to create a regular expression such that if given a C
signature, I can
# extract all of the parameter arguements
# e.g. for int print_date(char *date, char *month, char *year);
# I return say the following tuple -> ("char *date", "char *month",  "char
*year")

# The example below (tries to use !) groups where a given group would be
populated
# with each arguement. It only seems to match the last arguement.
# ... Can this apprach work ??.
# ... How can I get a match on all of the arguements ???.

args_from_signature = re.compile("^.* [\w]*?[(]((([^,]*?)[,]+)*?)[)][;]+",
re.DOTALL)

a = args_from_signature.match("int gg(int y);")
b = args_from_signature.match("int gg(int y, int z, int y, int p);")
c = args_from_signature.match("int ggz;")

print a
print b
print b.groups()






More information about the Python-list mailing list