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


Groups > comp.lang.python > #102780

Re: RegExp help

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Larry Martell <larry.martell@gmail.com>
Newsgroups comp.lang.python
Subject Re: RegExp help
Date Wed, 10 Feb 2016 22:09:51 -0500
Lines 48
Message-ID <mailman.27.1455160239.22075.python-list@python.org> (permalink)
References <CACwCsY6Lpt2DqwHz5bm2BV-aJmDbTvnv2kMVwq-W0mA1rcpQGw@mail.gmail.com> <56BBF935.9050902@mrabarnett.plus.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de hci+zVYPG4nzeVcal0sphg3/yTQiUnzVEg1wMvXs9/vA==
Return-Path <larry.martell@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'mrab': 0.05; 'skip:\\ 10': 0.07; 'subject:help': 0.07; 'arg': 0.09; 'sub': 0.09; 'wed,': 0.15; 'argument': 0.15; '10:00': 0.16; '2016': 0.16; 'count.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'string:': 0.16; 'wrote:': 0.16; 'thanks.': 0.18; 'to:name:python-list@python.org': 0.20; 'feb': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; '2.6': 0.27; 'larry': 0.29; 'skip:r 50': 0.29; 'print': 0.30; 'flags': 0.33; 'foo': 0.33; 'running': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'doing': 0.38; 'received:209': 0.38; 'turned': 0.38; 'to:addr:python.org': 0.40; '>>>>>': 0.66; '4th': 0.67; 'skip:| 10': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=eKEkf2sUGQXwACVygJOfAA1DJz1JfLwHZuClHgrfIfs=; b=im9iSN7Uvy+dzMgu1hIqkVoKI8fc7fpy2LXAb2RSE8NSepw+s+Qz/YTzJt8tu/w9zw L9SY8EvYfIJtR3d5GDRNVYbT/9CMwxbvjQYzorBnx258baH/ybiURqQXllVzKBjmmxGM zFWp50/yHfYkR+8kh2jKY9p2rWHtBJOluNJSwdZnRvj13Tfv6m46acKU7sEBxgxvOLd3 vYkjdGmDNpm87FBr5GQpgVUNJoiAzfD5hCDdeyoUK+5RQt3VYbEu1MCvrXh3WyR+CiYR Prwsb9AKOFKYGTEfqzEeyDVIUc7ll63Kx3BMax1JlLV+3VVQEv3hGxznzu3xaC4caYC/ bcsA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=eKEkf2sUGQXwACVygJOfAA1DJz1JfLwHZuClHgrfIfs=; b=nMtes2N5i4qZLy3UsCwy/1Puuj0yTHyDdiqyChaZhHGtQoB53ivb4llWeOd7SnI1xr uU+Q9Tad0a3oeSVVhBcp2Ix7XYd3KzabeY9AgZhY4clGsI/e7DwCtMwofEIWmDhhKfzF QqWn4lzNEL6xcqa0qM/wFMuk9xklGHeuT6k5SAEFzp/Y5DVDNrochrkrACyW0yLzyvjG 0h+ko7Elnw5QVF4hqQSH7Vk/qX2Ox+PCfi1LhMMIrTrcDC3n4ySSX5Yq6GpQSQK9YS70 4JrlsQSunDbS7o533gyZAJtjaddtu6qiRSf3+r6S5sCRGmcMEAPqGlaVc7n+gFM2ZcHf QdwA==
X-Gm-Message-State AG10YOReOuycYBjoo98YtCWWigpC1frfvsN7d6efyKrVzUZaZwFEfi4VC0DevZWExKzuuSeUNxYTQl/tNx2axw==
X-Received by 10.107.156.14 with SMTP id f14mr50342076ioe.0.1455160231221; Wed, 10 Feb 2016 19:10:31 -0800 (PST)
In-Reply-To <56BBF935.9050902@mrabarnett.plus.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102780

Show key headers only | View raw


On Wed, Feb 10, 2016 at 10:00 PM, MRAB <python@mrabarnett.plus.com> wrote:
> On 2016-02-11 02:48, Larry Martell wrote:
>>
>> 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?
>>
> The 4th argument of re.sub is the count.


Thanks. Turned out that this site is running 2.6 and that doesn't
support the flags arg to sub. So I had to change it to:

re.sub(r'\|Type=(.*)\n\|Side=(.*)', r'\|Side Type=\2 \1',s)

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: RegExp help Larry Martell <larry.martell@gmail.com> - 2016-02-10 22:09 -0500

csiph-web