Saroekin Saroekin - 5 months ago 7
Python Question

How to remove all characters before a specific character in Python?

I'd like to remove all characters before a designated character or set of characters (for example):

intro = "<>I'm Tom."


Now I'd like to remove the
<>
before
I'm
(or more specifically,
I
). Any suggestions?

Answer

Use re.sub. Just match all the chars upto I then replace the matched chars with I.

re.sub(r'.*I', 'I', stri)
Comments