I can do it in sed...

Kent Johnson kent37 at tds.net
Thu Mar 17 16:36:48 CET 2005

Kotlin Sam wrote:
>     Also, I frequently use something like s/^[A-Z]/~&/ to pre-pend a 
> tilde or some other string to the beginning of the matched string. I 
> know how to find the matched string, but I don't know how to change the 
> beginning of it while still keeping the matched part.

Something like
re.sub(r'^([A-Z])', r'~\1', target)
should do it.


More information about the Python-list mailing list