{"id":232,"date":"2008-09-05T07:22:18","date_gmt":"2008-09-05T14:22:18","guid":{"rendered":"http:\/\/www.rodgreen.com\/?p=232"},"modified":"2008-09-05T07:22:18","modified_gmt":"2008-09-05T14:22:18","slug":"useful-string-expressions-mel","status":"publish","type":"post","link":"https:\/\/www.rodgreen.com\/?p=232","title":{"rendered":"Useful string expressions (mel)"},"content":{"rendered":"<p>Collection of useful string expressions for mel<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;The nice name of an object from the &#8216;long&#8217; path<\/p>\n<div>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;|locator1|null1|pCube1&quot;;\nmatch(&quot;[^|]*$&quot;, $matchString);\n\n\/\/ Result: pCube1 \/\/<\/pre>\n<p>The parent of an object from the &#8216;long&#8217; path<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;|locator1|null1|pCube1&quot;;\nsubstitute(&quot;|[^|]*$&quot;, $matchString, &quot;&quot;);\n\n\/\/ Result: |locator1|null1 \/\/<\/pre>\n<p>Match the specified attribute name of an object<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;|locator1|null1|pCube1.translate&quot;;\nmatch(&quot;[^.]*$&quot;, $matchString);\n\n\/\/ Result: translate \/\/<\/pre>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;|locator1|null1|pCube1.vtx[0]&quot;;\nmatch(&quot;[^.]*$&quot;, $matchString);\n\n\/\/ Result: vtx[0] \/\/<\/pre>\n<p>Match the nice name of an object excluding any includeded attributes<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;|locator1|null1|pCube1.translate&quot;;\nmatch(&quot;[^|]*$&quot;, match(&quot;^[^.]*&quot;, $matchString));\n\n\/\/ Result: pCube1 \/\/<\/pre>\n<p>Match the attribute excluding any array index information<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;|locator1|null1|pCube1.vtx[0]&quot;;\nmatch(&quot;[^.]*$&quot;, match(&quot;^[^[]*&quot;, $matchString));\n\n\/\/ Result: vtx \/\/<\/pre>\n<p>Remove trailing character (i.e Whitespace, new line, tab etc)<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;text string nrt&quot;;\nsubstitute(&quot;[( ntr)]*$&quot;, $matchString, &quot;&quot;);\n\n\/\/ Result: text string \/\/<\/pre>\n<p>Remove leading character (i.e Whitespace, new line, tab etc)<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot; nrttext string&quot;;\nsubstitute(&quot;^[( ntr)]*&quot;, $matchString, &quot;&quot;);\n\n\/\/ Result: text string \/\/<\/pre>\n<p>Drive letter from path<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;c:\\testdir\\subdirectoryA\/subdirectoryB\/yourFile.txt&quot;;\nmatch(&quot;^[^:]*&quot;, $matchString);\n\n\/\/ Result: c \/\/<br \/><\/pre>\n<p>Full directory from path<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;c:\\testdir\\subdirectoryA\/subdirectoryB\/yourFile.txt&quot;;\nsubstitute(&quot;[^(\\\/)]*$&quot;, $matchString, &quot;&quot;);\n\n\/\/ Result: c:testdirsubdirectoryA\/subdirectoryB\/ \/\/<\/pre>\n<p>Full filename from path<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;c:\\testdir\\subdirectoryA\/subdirectoryB\/yourFile.txt&quot;;\nmatch(&quot;[^(\\\/)]*$&quot;, $matchString);\n\n\/\/ Result: yourFile.txt \/\/<\/pre>\n<p>File extension from path<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;c:\\testdir\\subdirectoryA\/subdirectoryB\/yourFile.txt&quot;;\nmatch(&quot;[^(.)]*$&quot;, $matchString);\n\n\/\/ Result: txt \/\/<\/pre>\n<p>Filename excluding extension from path<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;c:\\testdir\\subdirectoryA\/subdirectoryB\/yourFile.txt&quot;;\nmatch(&quot;^[^.]*&quot;, match(&quot;[^(\\\/)]*$&quot;, $matchString));;\n\n\/\/ Result: yourFile \/\/<br \/><\/pre>\n<p>Backslashes to forward slashes<\/p>\n<pre style=\"margin-left: 40px; \">\nstring $matchString = &quot;c:\\testdir\\subdirectoryA\/subdirectoryB\/yourFile.txt&quot;;\nsubstituteAllString($matchString, &quot;\\&quot;, &quot;\/&quot;);\n\n\/\/ Result: c:\/testdir\/subdirectoryA\/subdirectoryB\/yourFile.txt \/\/<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Collection of useful string expressions for mel<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,7,11,15],"tags":[54,37,41,56,58],"class_list":["post-232","post","type-post","status-publish","format-standard","hentry","category-art","category-maya-art","category-technical-art","category-tutorials","tag-maya-art","tag-mel","tag-python","tag-technical-art","tag-tutorials"],"_links":{"self":[{"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/posts\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=232"}],"version-history":[{"count":0,"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}