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?
[code]
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:
paramPairs.append(s)
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]
params.append((type_,name))
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?
Thanks,
Jason