import re
def customerStrip(steament, string):
'''
:param steament: 被过滤的字符串
:param string: 要过滤的字符
:return: 返回过滤后的数据
'''
string = '\\' + string
customerRegex = re.compile(r'^(((' + string + ')*)?(\s*))(.*?)((\s*)?((' + string + ')*))$')
try:
moCustome = customerRegex.search(steament).groups()
return moCustome[4]
except AttributeError:
return '不存在要过滤的字符!'
text = '####3213213###'
print(customerStrip(text, '#'))
自己练习写的很不完善。
经测试,strip 这是这个自定义函数customerStrip的80多倍,很差劲,方法写的不好
import re
import time
def leftRegex(steament, string):
lRgex = re.compile(r'(^(' + string + ')*)')
moLeft = lRgex.search(steament).group()
return moLeft
def rightRegex(steament, string):
rRe