Dealing with regular expressions, Python
Posted
by
Gusto
on Stack Overflow
See other posts from Stack Overflow
or by Gusto
Published on 2010-11-06T15:25:57Z
Indexed on
2010/12/28
12:54 UTC
Read the original article
Hit count: 232
I want to remove some symbols from a string using a regular expression, for example:
==
(that occur both at the beginning and at the end of a line),
*
(at the beginning of a line ONLY).
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.
What's wrong with my code? It seems like expressions are wrong. How do I remove a character/symbol if it's at the beginning or at the end of the line (with one or more occurrences)?
© Stack Overflow or respective owner