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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 2012/12/30 Helmut Jarausch : > 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