Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

I want to remove all characters before a designated character or set of characters. For example :

intro = "<>I'm Tom."

Now What to do if I want to remove the <> before I'm ?

1 Answer

0 votes
by (25.1k points)
edited by

The problem you are explaining can be easily solved using regular expressions in python. In python you can use the re module to perform tasks relating to regular expressions.

For the problem that you have outlined, you can use the sub method from the re module in python. The sub method substitutes anything that matches a given pattern with a given string, like this:

re.sub(r'.*I', 'I', string)

If you wish to get a deeper understanding of python you can take a look at this, youtube video:

Browse Categories

...