[Tutor] Multiple search and replace?

Andy McKenzie amckenzie4 at gmail.com
Thu May 2 19:16:54 CEST 2013


Hey folks,

  I'm trying to figure out how to do something, and it feels like it should
be possible, but I can't figure out how.  What I want is to define four
expressions, like so:

(\sNorth\s|\sN\s)(\sSouth\s|\sS\s)(\sEast\s|\sE\s)(\sWest\s|\sW\s)

And then run a replace such that the groups are replaced, in order, with "N
", "S ", "E ", or "W " (capital letters, no spaces before).

It's easy enough to use re.sub to replace ONE of those, and I could just do
that four times, but is there a way to do all at once?  It looks from some
things I've seen like it should be, but I can't figure out how.

Thanks,
  Andy McKenzie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130502/29c3d22d/attachment.html>


More information about the Tutor mailing list