fork(1) download
  1. import re
  2.  
  3. def regexstrip(string, _strip=None):
  4. _strip = r"\A[\s{0}]+|[\s{0}]+\Z".format(re.escape(_strip)) if _strip else r"\A\s+|\s+\Z"
  5. print(_strip) #just for troubleshooting
  6. return re.sub(_strip, '', string)
  7.  
  8. print(regexstrip(" ([no more stripping'] ) ", " ()[]'"))
  9. print(regexstrip(" ([no more stripping'] ) "))
Success #stdin #stdout 0.03s 9936KB
stdin
Standard input is empty
stdout
\A[\s\ \(\)\[\]\']+|[\s\ \(\)\[\]\']+\Z
no more stripping
\A\s+|\s+\Z
([no more stripping']  )