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 am trying to use multi-line mode in the Python library re.
The syntax of the MATLAB function is as follows:
function output = func_name(input)
where the signature can span multiple lines.
I started with a template like:
re.compile(r"^.*function (.*)=(.*)\([.\n]*\)$", re.M)
but I keep getting unsupported template statement error. Any pointer is appreciated!
EDIT:
Now I have:
pattern = re.compile(r"^\s*function (.*?)= [\w\n.]*?\(.*?\)", re.M|re.DOTALL)
which gives matches:
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 extra lines instead of stopping at the first )?
source
share