Multiline regex

Jeremy Sanders jeremy at jeremysanders.net
Wed Jul 21 12:56:16 EDT 2010


Brandon Harris wrote:

> I'm trying to read in and parse an ascii type file that contains
> information that can span several lines.
> Example:

What about something like this (you need re.MULTILINE):

In [16]: re.findall('^([^ ].*\n([ ].*\n)+)', a, re.MULTILINE)
Out[16]: 
[('createNode animCurveTU -n "test:master_globalSmooth";\n    setAttr ".tan" 
9;\n    setAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;\n    setAttr -s 4 
".kit[3]"  10;\n    setAttr -s 4 ".kot[3]"  10;\n',
  '    setAttr -s 4 ".kot[3]"  10;\n'),
 ('createNode animCurveTU -n "test:master_res";\n    setAttr ".tan" 9;\n    
setAttr ".ktv[0]"  103 0;\n    setAttr ".kot[0]"  5;\n',
  '    setAttr ".kot[0]"  5;\n'),
 ('createNode animCurveTU -n "test:master_faceRig";\n    setAttr ".tan" 9;\n    
setAttr ".ktv[0]"  103 0;\n',
  '    setAttr ".ktv[0]"  103 0;\n')]

If you blocks start without a space and subsequent lines with a space.

Jeremy





More information about the Python-list mailing list