Combining regular expressions

I’m trying to combine several regular expressions in to one single expression which does all of them at once. Right now I have the following code (in python because I have to make it work in more than just Xojo :/) which successively drills down towards the final result of extracting the name and type of a function’s parameters from a C header file. Is there some way to combine all of this logic into a single regular expression?

import re

example = “bool MyFunction(MyStructure * hdl, unsigned long responseTimeout, const char * workingDir, unsigned long fifoSize, bool debugMode);”

fcnAllParams = r"(?<=\().(?=\))" # to get everything inside the ()
fcnParamPairs = r"[^\,
" # to split on ,
matches= re.findall(fcnAllParams,example)

paramPairs = []
for match in matches:
submatches = re.findall(fcnParamPairs,match)
for s in submatches[:-1]:
if len(s) != 0:

paramType = r".*(?= )" # to get up to the last space (type)
paramName = r"[^ ]+$" # to get everything after the last space (name)
params = []
for pair in paramPairs:
name = re.findall(paramType,pair)[0]
type_ = re.findall(paramName,pair)[0]

process params[/code]

More than just combining it for this example is there a way to do this for any arbitrary set of regular expressions which depend on each other’s results?


The problem is, you don’t know how many results to expect back because there may be 0 parameters, or there might be 6 parameters. Regular expression groups must be defined so they are not well -suited for returning arbitrary results. In other words, no, you have to keep drilling down.

I do recommend that you replace “." with more specific tokens like "[^)]”.

And then someone tosses you a header that has “char *” in it and it may be a pointer to a C string - or not - and you actually have to examine the code (r maybe docs - lord let there be doc) to know if it really is a c string or if its used some other way

And to add more fun they give you a “void *”