[Tutor] Regular expression grouping insert thingy

Matthew Wood woodm1979 at gmail.com
Wed Jun 9 06:17:59 CEST 2010

re.sub(r'(\d+)x', r'\1*x', input_text)


I enjoy haiku
but sometimes they don't make sense;

On Tue, Jun 8, 2010 at 10:11 PM, Lang Hurst <lang at tharin.com> wrote:

> This is so trivial (or should be), but I can't figure it out.
> I'm trying to do what in vim is
> :s/\([0-9]\)x/\1*x/
> That is, "find a number followed by an x and put a "*" in between the
> number and the x"
> So, if the string is "6443x - 3", I'll get back "6443*x - 3"
> I won't write down all the things I've tried, but suffice it to say,
> nothing has done it.  I just found myself figuring out how to call sed and
> realized that this should be a one-liner in python too.  Any ideas?  I've
> read a lot of documentation, but I just can't figure it out.  Thanks.
> --
> There are no stupid questions, just stupid people.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100608/b8551df1/attachment.html>

More information about the Tutor mailing list