Search code examples
regexstringtclstrip

TCL Strip expression (Varying chars)


If i have a string such as:

foo_image_v001.ext

that could just as easily say

bar_image_v001.ext

How can i use TCL to strip the first underscore and everything to the right of it, leaving me with just 'foo' or 'bar'

Im normally a python guy, not very versed in TCL, but it will work best in this case if i can just get it to work =)


Solution

  • Replace everything after the first _

    set new [regsub {_.*} $old {}]