How do I use a Python regex to match the function syntax of MATLAB? -


I am trying to find all input / output of all MATLAB functions in my internal library. I'm trying regex and new to use margin mode in Python's again library.

The MATLAB function syntax looks like this:

  function output = funny_nm (input)  

where signatures can span multiple lines is.

I started with a pattern:

  re.compile (r "^. * Function (. *) = (. *) \ ([. \ N ] * \) $ ", Re.M  

but I'm getting an unsupported template operator error. Any pointer is appreciated!

Edit:

I now have:

  pattern = re.compile (r "^ \ S * Function (. *?) = [\ W \ n.] *? \ (. *? \) ", Re.m. re.Dotal)  

which gives matches Like:

  function [fcst, spread] = ... wolfstastmkeyt (r, ... mktVol, ... check, spread ..., ... fcstdays, ... Tsperyear if (calibrate) if (Nargin and lieutenant; 6) tsperyear = 252; Last temp = length (r)  

My question is why does he first give additional row instead of stopping ) ?

If you are receiving a strange (internal) error occurs, Instead of re.m as re.compile ( re.template - currently using undocumented entry - Intended, and, in short, templates do not support RE repeat or back tracking). What can you value in your code before calling re.compile

Once fixed, we can discuss your desired Details of RE (in essence: if particles can be included in input part, otherwise again. DOTALL and some of your patterns should be written) - but this strange internal Deciding the occurrence of an error takes priority.

Edit : With the diagnosis of this bug (according to the comment below this Q), OP current question: re.Dotal at the end of the pattern Again Multitain , plus '$', plus everywhere-using Greedy Match (. * , instead of . *? for non-greedy), Be sure to all together that if regex matches, it will probably match widely as a swathe ... that's exactly what the combo is asking for. Probably the best to open the second question with a specific example: what is the input, what does the match, you like instead of regex to match, etc.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -