{"id":177,"date":"2008-09-05T07:07:27","date_gmt":"2008-09-05T14:07:27","guid":{"rendered":"http:\/\/www.rodgreen.com\/?page_id=177"},"modified":"2008-09-05T07:07:27","modified_gmt":"2008-09-05T14:07:27","slug":"useful-string-expressions-mel","status":"publish","type":"page","link":"https:\/\/www.rodgreen.com\/?page_id=177","title":{"rendered":"Useful string expressions (mel)"},"content":{"rendered":"<p>The nice name of an object from the &#8216;long&#8217; path<\/p>\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 \/\/<br \/><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The nice name of an object from the &#8216;long&#8217; path string $matchString = &quot;|locator1|null1|pCube1&quot;; match(&quot;[^|]*$&quot;, $matchString); \/\/ Result: pCube1 \/\/ The parent of an object from the &#8216;long&#8217; path string $matchString = &quot;|locator1|null1|pCube1&quot;; substitute(&quot;|[^|]*$&quot;, $matchString, &quot;&quot;); \/\/ Result: |locator1|null1 \/\/ Match the specified attribute name of an object string $matchString = &quot;|locator1|null1|pCube1.translate&quot;; match(&quot;[^.]*$&quot;, $matchString); \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":172,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-177","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/pages\/177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"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=177"}],"version-history":[{"count":0,"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/pages\/177\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=\/wp\/v2\/pages\/172"}],"wp:attachment":[{"href":"https:\/\/www.rodgreen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}