Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102778 > unrolled thread

RegExp help

Started byLarry Martell <larry.martell@gmail.com>
First post2016-02-10 21:48 -0500
Last post2016-02-10 21:48 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  RegExp help Larry Martell <larry.martell@gmail.com> - 2016-02-10 21:48 -0500

#102778 — RegExp help

FromLarry Martell <larry.martell@gmail.com>
Date2016-02-10 21:48 -0500
SubjectRegExp help
Message-ID<mailman.25.1455158974.22075.python-list@python.org>
Given this string:

>>> s = """|Type=Foo
... |Side=Left"""
>>> print s
|Type=Foo
|Side=Left

I can match with this:

>>> m = re.search(r'^\|Type=(.*)$\n^\|Side=(.*)$',s,re.MULTILINE)
>>> print m.group(0)
|Type=Foo
|Side=Left
>>> print m.group(1)
Foo
>>> print m.group(2)
Left

But when I try and sub it doesn't work:

>>> rn = re.sub(r'^\|Type=(.*)$^\|Side=(.*)$', r'|Side Type=\2 \1',s,re.MULTILINE)
>>> print rn
|Type=Foo
|Side=Left

What very stupid thing am I doing wrong?

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web