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


Groups > comp.lang.python > #35806

Re: ignore case only for a part of the regex?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <vlastimil.brom@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'url:pypi': 0.03; 'case.': 0.05; 'elegant': 0.07; 'python': 0.09; 'ignoring': 0.09; 'subject:ignore': 0.09; 'subject:case': 0.16; 'specify': 0.17; '>>>': 0.18; 'bit': 0.21; 'import': 0.21; "i've": 0.23; 'allows': 0.25; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'compiled': 0.27; 'message-id:@mail.gmail.com': 0.27; 'way?': 0.29; 'url:mailman': 0.29; '"the': 0.29; "skip:' 10": 0.30; 'e.g.': 0.30; 'url:python': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'received:209.85.220': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'apply': 0.39; 'header:Received:5': 0.40; 'url:mail': 0.40; 'different': 0.63; 'more': 0.63; 'compose': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=sauYEmAAKWXnBQegUwsCYtPmFiPFEt18Z7e3UwFE5Ok=; b=SqfSre76ashp3Y/VwAy/M35JUudRcykqHzI2Ogzr8DoaNEp/5BtZtYVlO6vKUPNS0j nNZarp+668hn0xjFSWe9Wrp4bSqt1FtvxgKIqvq3JC88xcEyhTyoZYCAQ2wNAMSrrjIm q3fsbTV4Ri7QyOFn9bvdzDa3yeG41p0mM/GNDkSskj9NCFMFDKwLK4vZIEnWqK1p1lSz fbXAbBV3BwIpLvzlsOFq/qHnDobn9B8ts1OBaM0ClEUqsZEJlCCFZYzgibpBKEEZW1VF 4kmSMbJ2yoGonMD98x0qbt7cnwReqwl4gGpcYKnIX5pY0oQC/2knlHiw4ZTG+58gny1R l8QA==
MIME-Version 1.0
In-Reply-To <50e02485$0$3109$ba620e4c@news.skynet.be>
References <50e02485$0$3109$ba620e4c@news.skynet.be>
Date Sun, 30 Dec 2012 17:38:31 +0100
Subject Re: ignore case only for a part of the regex?
From Vlastimil Brom <vlastimil.brom@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1467.1356885520.29569.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1356885520 news.xs4all.nl 6901 [2001:888:2000:d::a6]:60032
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35806

Show key headers only | View raw


2012/12/30 Helmut Jarausch <jarausch@skynet.be>:
> Hi,
>
> is there a means to specify that 'ignore-case' should only apply to a part
> of a regex?
>
> E.g.
>
> the regex should match  Msg-id:, Msg-Id, ...  but not  msg-id: and so on.
>
> I've tried the pattern
> r'^Msg-(?:(?i)id):'
> but (?i) makes the whole pattern ignoring case.
>
> In my simple case I could say
> r'Msg-[Ii][Dd]:'
> but that's a bit clumsy.
>
> Is there a more elegant way? Is there a way to compose a pattern
> from subpatterns which are compiled with different flags?
>
> Many thanks for a hint,
> Helmut.
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,
you may check the new regex implementation for python
http://pypi.python.org/pypi/regex
which allows (among many other improvements) for scoped flags:

>>> import regex
>>> regex.findall(r"Msg-(?i:id):", "the regex should match  Msg-id:, Msg-Id:, ...  but not  msg-id:, MSG-ID:  and so on")
['Msg-id:', 'Msg-Id:']
>>>

hth,
 vbr

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


Thread

re: ignore case only for a part of the regex? Helmut Jarausch <jarausch@skynet.be> - 2012-12-30 11:24 +0000
  Re: ignore case only for a part of the regex? Roy Smith <roy@panix.com> - 2012-12-30 10:20 -0500
    Re: ignore case only for a part of the regex? Joel Goldstick <joel.goldstick@gmail.com> - 2012-12-30 10:41 -0500
    Re: ignore case only for a part of the regex? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-01 04:14 +0000
      Re: ignore case only for a part of the regex? Vlastimil Brom <vlastimil.brom@gmail.com> - 2013-01-02 00:09 +0100
        Re: ignore case only for a part of the regex? wxjmfauth@gmail.com - 2013-01-02 06:17 -0800
        Re: ignore case only for a part of the regex? wxjmfauth@gmail.com - 2013-01-02 06:17 -0800
  Re: ignore case only for a part of the regex? Vlastimil Brom <vlastimil.brom@gmail.com> - 2012-12-30 17:38 +0100
    Re: ignore case only for a part of the regex? Roy Smith <roy@panix.com> - 2012-12-30 12:32 -0500
      Re: ignore case only for a part of the regex? MRAB <python@mrabarnett.plus.com> - 2012-12-30 18:04 +0000
      Re: ignore case only for a part of the regex? Cameron Simpson <cs@zip.com.au> - 2012-12-31 11:29 +1100

csiph-web