PDA

View Full Version : Regular Expression in python


TITANius
10-30-2010, 08:24 PM
How to separate Mesh and faceIndex from string
pPlaneShape1.f[1]Need to get the two variables: "pPlaneShape1" and "1"

skeelogy
10-31-2010, 07:23 AM
Hi TITANius,

This will do the trick:
import re
m = re.search('(\w+)\.f\[(\d+)\]', 'pPlaneShape1.f[1]')
print m.groups()Hope this helps!

TITANius
10-31-2010, 07:58 AM
Hi TITANius,
This will do the trick:
import re
m = re.search('(\w+)\.f\[\(d+)\]', 'pPlaneShape1.f[1]')
print m.groups()error :(

# Error: line 0: error: file C:\Program Files\Autodesk\Maya2011\bin\python26.zip\re.py line 245: unbalanced parenthesis #

skeelogy
10-31-2010, 08:02 AM
Oops sorry, misplaced one of the backslashes. I've edited the post. Try again!

TITANius
10-31-2010, 08:11 AM
Oops sorry, misplaced one of the backslashes. I've edited the post. Try again!
works, thanks :)

TITANius
10-31-2010, 08:29 AM
What's wrong in my code?
from pymel.core import *
import re

Faces=ls(fl=1,sl=1)
for Face in Faces:
m = re.search('(\w+)\.f\[(\d+)\]', Face)
print m.groups()error

# Error: line 0: TypeError: file C:\Program Files\Autodesk\Maya2011\bin\python26.zip\re.py line 142: expected string or buffer #

TITANius
10-31-2010, 08:39 AM
Figured out:)

Need to be translated into a string
from pymel.core import * import re
Faces=ls(fl=1,sl=1)
for Face in Faces:
m = re.search('(\w+)\.f\[(\d+)\]', str(Face))
print m.groups()

CGTalk Moderation
10-31-2010, 08:39 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.