import re
def strip(text, chars=None):
"""去除首尾的字符
:type text: string
:type chars: string
:rtype: string
"""
if chars is None:
_ reg = re.compile('^ *| *$')#不懂意思,*新的用法嘛?_
else:
reg = re.compile('[' + chars + ']*|[' + chars + ']*')
return reg.sub('', text)
print(strip(' 123456 '))
print(strip(' 123456'))
print(strip(' 123456'))
print(strip('123456 654321'))
print(strip('123456 654321', '1'))
print(strip('123456 654321', '1234'))
print(strip('123456 654321', '124'))
中的('^ *| *$')这个正则表达式怎么解释呢?求解