PDA

View Full Version : regular expression help


neonoodle
09-07-2005, 11:25 PM
Hey all,
I'm having a hard time figuring out regular expressions. How can I replace all instances of a string with another string? Say I have an object named "sphere_poly_poly" and I want to replace "poly" with "nurbs", I tried:

substitute "(poly)+" $object "nurbs";

but it only replaces the first instance and gives me "sphere_nurbs_poly"

any suggestions?

Thanks!

pk_pk
09-08-2005, 06:22 PM
hi,

too bad substitue doesn't replace all occurances. maybe u can do something like this:


global proc string replaceStr(string $object)
{
string $t = "";
while(true)
{
int $matchPoly = `gmatch $object "*poly*"`;
if(!$matchPoly)
{
break;
}
$t = evalEcho("substitute \"(poly)+\" " + $object + " \"nurbs\"");
$object = $t;
}
print ("Replaced str: " + $object + "\n");
return $object;
}
string $object = "sphere_poly_poly";
string $newStr = replaceStr($object);

CGTalk Moderation
09-08-2005, 06:22 PM
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.