MEL How-To #94 | ||
| ||
Useful Regular Expressions for MELStrip componentstring $node = "pCube1.f[2]"; string $no_component = `match "^[^\.]*" $node`; // Result: "pCube1" // Extract component or attribute, with '.'string $node = "pCube1.f[2]"; string $component = `match "\\..*" $node`; // Result: ".f[2]" // string $nodeAttr = "blinn1.color"; string $attrName = `match "\\..*" $nodeAttr`; // Result: ".color" // Extract attribute name, without '.'string $node = "pCube1.f[2]"; string $component = `substitute "^[^.]*\\." $node ""`; // Result: "f[2]" // string $nodeAttr = "blinn1.color"; string $attrName = `substitute "^[^.]*\\." $nodeAttr ""`; // Result: "color" // Extract parent UI control from full pathstring $uiControl = "OptionBoxWindow|formLayout52|formLayout55|button6"; string $uiParent = `substitute "|[^|]*$" $uiControl ""`; // Result: OptionBoxWindow|formLayout52|formLayout55 // Strip trailing CR, if anyThis is useful when processing text input read from a file using ‘ string $input = "line\n"; $string $line = `match "^[^(\r\n)]*" $input`; // Result: "line" // Extract directory from pathNote that this leaves a trailing slash. This is typically desired, as it makes it easy to simply
append a filename, and the slash is required for the ‘ string $path = "C:/AW/Maya5.0/bin/maya.exe"; string $dir = `match "^.*/" $path`; // Result: "C:/AW/Maya5.0/bin/" Extract file from pathstring $path = "C:/AW/Maya5.0/bin/maya.exe"; string $filepart = `match "[^/\\]*$" $path`; // Result: "maya.exe" Strip numeric suffixstring $node = "pCube1|pCubeShape223"; string $noSuffix = `match ".*[^0-9]" $node`; // Result: "pCube1|pCubeShape" Extract numeric suffixstring $node = "pCube1|pCubeShape223"; string $suffix = `match "[0-9]+$" $node`; // Result: "223" // Extract short name of DAG or control pathstring $dagPath = "pCube1|pCubeShape223"; string $shortName = `match "[^|]*$" $dagPath`; // Result: pCubeShape223 // | ||
Copyright ©2005 by Bryan Ewert, maya@ewertb.com Maya is a Registered Trademark of Alias |