我想使用正则表达式从字符串中删除一些符号,例如:
==
(在行的开头和结尾都出现),
*
(仅在行的开头出现)。
def some_func():
clean = re.sub(r'= {2,}', '', clean) #Removes 2 or more occurrences of = at the beg and at the end of a line.
clean = re.sub(r'^\* {1,}', '', clean) #Removes 1 or more occurrences of * at the beginning of a line.
我的代码出了问题,看起来表达式有误。如果一个字符/符号位于行首或行尾(具有一个或多个出现),我该如何去除它?
s.strip('=').lstrip('*').strip()
- Nick Presta