I am trying to find all the inputs/outputs of all MATLAB functions in our internal library. I am new (first time) to regex and have been trying to use the multiline mode in Python's re
library.
The MATLAB function syntax looks like:
function output = func_name(input)
where the signature can span multiple lines.
I started with a pattern like:
re.compile(r"^.*function (.*)=(.*)\([.\n]*\)$", re.M)
but I keep getting an unsupported template operator error. Any pointer is appreciated!
EDIT:
Now I have:
pattern = re.compile(r"^\s*function (.*?)= [\w\n.]*?\(.*?\)", re.M|re.DOTALL)
which gives matches like:
function [fcst, spread] = ...
VolFcstMKT(R,...
mktVol,...
calibrate,...
spread_init,...
fcstdays,...
tsperyear)
if(calibrate)
if(nargin < 6)
tsperyear = 252;
end
templen = length(R)
My question is why does it give the extra lines instead of stopping at the first )
?