Multiline regex

B

Brandon Harris

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

createNode animCurveTU -n "test:master_globalSmooth";
setAttr ".tan" 9;
setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
setAttr -s 4 ".kit[3]" 10;
setAttr -s 4 ".kot[3]" 10;
createNode animCurveTU -n "test:master_res";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;
createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;

I'm wanting to grab the information out in chunks, so

createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;

would be what my regex would grab.
I'm currently only able to grab out the first line and part of the
second line, but no more.
regex is as follows

my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")

I've run several variations of this, but none return me all of the
expected information.

Is there something special that needs to be done to have the regexp grab
any number of the setAttr lines without specification?

Brandon L. Harris
 
P

Peter Otten

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

createNode animCurveTU -n "test:master_globalSmooth";
setAttr ".tan" 9;
setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
setAttr -s 4 ".kit[3]" 10;
setAttr -s 4 ".kot[3]" 10;
createNode animCurveTU -n "test:master_res";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;
createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;

I'm wanting to grab the information out in chunks, so

createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;

would be what my regex would grab.
I'm currently only able to grab out the first line and part of the
second line, but no more.
regex is as follows

my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")

I've run several variations of this, but none return me all of the
expected information.

Is there something special that needs to be done to have the regexp grab
any number of the setAttr lines without specification?

Groups are marked with parens (...) not brackets [...].
.... createNode animCurveTU -n "test:master_globalSmooth";
.... setAttr ".tan" 9;
.... setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
.... setAttr -s 4 ".kit[3]" 10;
.... setAttr -s 4 ".kot[3]" 10;
.... createNode animCurveTU -n "test:master_res";
.... setAttr ".tan" 9;
.... setAttr ".ktv[0]" 103 0;
.... setAttr ".kot[0]" 5;
.... createNode animCurveTU -n "test:master_faceRig";
.... setAttr ".tan" 9;
.... setAttr ".ktv[0]" 103 0;
.... setAttr ".kot[0]" 5;
.... """.... print m.group(1)
.... print "-" * 40
....
createNode animCurveTU -n "test:master_globalSmooth";
setAttr ".tan" 9;
setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
setAttr -s 4 ".kit[3]" 10;
setAttr -s 4 ".kot[3]" 10;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top