String Replacement

Chris Angelico rosuav at gmail.com
Mon Jan 23 16:30:45 EST 2017


On Tue, Jan 24, 2017 at 8:23 AM,  <subhabangalore at gmail.com> wrote:
> I have a string like
>
> "Trump is $ the president of USA % Obama was $ the president of USA % Putin is $ the premier of Russia%"
>
> Here, I want to extract the portions from $...%, which would be
>
> "the president of USA",
> "the president of USA",
> "the premier of Russia"
>
> and would work some post extraction jobs, like I may split them or annotate them and may replace them
> back to its own position with the edited string.
>

The simplest solution would be a regex. Have a shot at it and see how
you go; if you get stuck, post code.

> I am using Python2.7.12 on MS-Windows 7

Any particular reason you're not using Python 3?

ChrisA


More information about the Python-list mailing list