Change first occurrence of character x in a string - how?

Dan Stromberg drsalists at gmail.com
Sun Feb 14 16:36:28 EST 2021


Check out re.sub's "count" parameter.

https://stackoverflow.com/questions/3951660/how-to-replace-the-first-occurrence-of-a-regular-expression-in-python

On Sun, Feb 14, 2021 at 1:20 PM Chris Green <cl at isbd.net> wrote:

> What's the easiest way to change the first occurrence of a specified
> character in a string?
>
> E.g. I want to change linux-raid.vger.kernel.org to
> linux-raid at vger.kernel.org, it's a fairly general requirement of
> needing to change '.' to '@'.
>
> Alternatively is there an RE 'match' function that would test if
> linux-raid at vger.kernel.org matches linux-raid.vger.kernel.org? I don't
> really care if the '.' are all regarded as wild cards, the match will
> be accurate enough.
>
> --
> Chris Green
> ·
> --
> https://mail.python.org/mailman/listinfo/python-list
>


More information about the Python-list mailing list