<p>我想使用正则表达式从字符串中删除一些符号,例如:</p>
<p><code>==</code>(出现在一行的开头和结尾)</p>
<p><code>*</code>(仅在行首)。</p>
<pre><code>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.
</code></pre>
<p>我的密码怎么了?似乎表达是错误的。如果字符/符号位于行的开头或结尾(出现一个或多个),如何删除该字符/符号?</p>