>>> def strip_upto_max(astring, pattern):
"${astring##*pattern}"
return astring.rpartition(pattern)[2]
>>> def strip_from_max(astring, pattern):
"${astring%%pattern*}"
return astring.partition(pattern)[0]
>>> def strip_upto(astring, pattern):
"${astring#*pattern}"
return astring.partition(pattern)[2]
>>> def strip_from(astring, pattern):
"${astring%pattern*}"
return astring.rpartition(pattern)[0]
>>> strip_from("hello there", " t")
'hello'
>>> strip_upto("hello there", " t")
'here'
>>> text= "left/middle/right"
>>> strip_from(text, "/")
'left/middle'
>>> strip_upto(text, "/")
'middle/right'
>>> strip_upto_max(text, "/")
'right'
>>> strip_from_max(text, "/")
'left'
, , os.path.dirname (${name%/*}) os.path.basename (${name##*/}) .