offtopic but i need help (little) - maya MEL RegEx question

37 views
Skip to first unread message

lala

unread,
Jul 5, 2014, 2:21:34 AM7/5/14
to python_in...@googlegroups.com
i have a string like "blabla_blabla_charName"

i want to strip / remove "_charName" from end...

one attempt is
string $saveFileName = `substitute "^[^.]*\\_" $saveFileString ""`; // it retuns "charName"
i know, its almost opposite to what i need
thanks in advance 

Justin Israel

unread,
Jul 5, 2014, 2:36:53 AM7/5/14
to python_in...@googlegroups.com
Strip the "_charName" part from the end of the given string:
substitute "_charName$" "blabla_blabla_charName" "";
// Result: blabla_blabla //


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d1c2b462-f371-4196-9db6-11ac304255f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin Israel

unread,
Jul 5, 2014, 2:40:53 AM7/5/14
to python_in...@googlegroups.com
More specifically, with a variable substitution:
string $charName = "charName"
string $source = "blabla_blabla_charName";

string $stripped = `substitute ("_" + $charName + "$") $source ""`;
// Result: blabla_blabla //

lala

unread,
Jul 5, 2014, 2:41:21 AM7/5/14
to python_in...@googlegroups.com
sorry, my bad explanation. charName is variable and changing. i wanted to ask, about stripping last part with underscore via regex. but thanks anyways

Justin Israel

unread,
Jul 5, 2014, 2:55:36 AM7/5/14
to python_in...@googlegroups.com

That's what my second reply shows. I stored the substring in $charName and then stripped it. That's what you wanted right?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

lala

unread,
Jul 5, 2014, 3:16:23 AM7/5/14
to python_in...@googlegroups.com
string $srcFile = "blabla_blabla_charName.fbx";
string $saveFileString = basename( $srcFile, ".fbx" );
string $charName = "_" + `substitute "^[^.]*\\_" $saveFileString ""`;
string $saveFileName = `substitute $charName $saveFileString ""`;
print $saveFileName;

apparently its solved now with your help. but if you look at line 3, its cheap (adding "underscore manually"). but atleast its working.
generally, i am sure, regex in line 3 again (second part) can solve it..but still, thanks anyways, really appriciate your prompt responses. always. thats only reason, posting here is more fun than anywhere else. 

On Saturday, 5 July 2014 11:55:36 UTC+5, Justin Israel wrote:

 That's what you wanted right?

Justin Israel

unread,
Jul 5, 2014, 4:00:12 AM7/5/14
to python_in...@googlegroups.com
Oh ok. You didn't actually have the charName value and you just want to remove the last component separated by an underscore. 
I don't really see the reason to try and first parse the token out of the string, and then use it to remove it from the original. You can just use a regex to strip it:
string $srcFile = "blabla_blabla_charName.fbx";
string $saveFileString = basename( $srcFile, ".fbx"
 );
string $saveFileName = `substitute "_[a-zA-Z0-9]+$" $saveFileString ""`;
Or you can completely avoid regular expression and just split the string on underscore, and join it back without the last component:
string $srcFile = "blabla_blabla_charName.fbx";
string $tokens[];
int $size = tokenize($srcFile, "_", $tokens);
stringArrayRemoveAtIndex($size-1, $tokens);
string $saveFileName = stringArrayToString($tokens, "_");



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

haseeb ahmed

unread,
Jul 5, 2014, 6:05:35 AM7/5/14
to python_inside_maya
wow, its amazing. thank you sir, its perfect. i owe you a drink . regards,lala


--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/tTDvkKKRX0w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1fq6A7%2Bc5UoJ7YddPkQO1TC97ETLA1R%2BhiQgzX%3DOL6CA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
regards,
lala

Justin Israel

unread,
Jul 5, 2014, 6:46:51 AM7/5/14
to python_in...@googlegroups.com

Anytime. And if we meet, a decent Rum will suit just fine ☺

Reply all
Reply to author
Forward
0 new messages