import re
def Strip(str_1, str_2= ''):
if str_2:
stripRegex = re.compile(str_2)
mo = stripRegex.sub('', str_1)
return mo
else:
stripRegex = re.compile(r'^(\s*)(.*)(\s*)$')
mo = stripRegex.search(str_1)
return mo.group(2)
print(Strip(' abasdfa '))
print(Strip(' abasdfa ', 'a'))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)