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


Groups > comp.lang.python > #48364

Re: Pattern Search Regular Expression

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'intermediate': 0.07; 'matches': 0.07; 'suppose': 0.07; 'string': 0.09; 'alter': 0.09; 'expectation': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; '"from': 0.16; 'differs': 0.16; 'experiment.': 0.16; 'interpreter,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:Regular': 0.16; 'words.': 0.16; 'wrote:': 0.18; 'slightly': 0.19; 'written': 0.21; 'header:User-Agent:1': 0.23; '(for': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'extract': 0.31; 'extend': 0.32; 'regular': 0.32; 'run': 0.32; 'beginning': 0.33; 'third': 0.33; 'editor': 0.35; 'add': 0.35; 'idle': 0.36; 'like,': 0.36; 'should': 0.36; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'easy': 0.60; 'expression': 0.60; 'received:173': 0.61; 'first': 0.61; 'times': 0.62; 'email addr:gmail.com': 0.63; 'such': 0.63; 'beat': 0.68; 'hints': 0.68; 'ending': 0.78; 'received:fios.verizon.net': 0.84; 'subject:Search': 0.84; '(i)': 0.91; '(ii)': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Pattern Search Regular Expression
Date Sat, 15 Jun 2013 16:24:15 -0400
References <afd6b280-3b64-467b-a2e1-2b36377cd13a@googlegroups.com> <51bc3c4d$0$29997$c3e8da3$5496439d@news.astraweb.com> <kphfdr$su9$8@dont-email.me> <mailman.3371.1371293740.3114.python-list@python.org> <kphqu1$su9$10@dont-email.me> <kphr62$su9$11@dont-email.me> <mailman.3377.1371306538.3114.python-list@python.org> <5200649f-2b2f-4535-8016-a31369e6e348@googlegroups.com> <mailman.3380.1371308712.3114.python-list@python.org> <2f83304f-8b4c-4af5-9fea-ec894a1b6401@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
In-Reply-To <2f83304f-8b4c-4af5-9fea-ec894a1b6401@googlegroups.com>
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.3404.1371327873.3114.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371327873 news.xs4all.nl 15965 [2001:888:2000:d::a6]:47954
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48364

Show key headers only | View raw


On 6/15/2013 12:28 PM, subhabangalore@gmail.com wrote:

> Suppose I want a regular expression that matches both "Sent from my iPhone" and "Sent from my iPod". How do I write such an expression--is the problem,
> "Sent from my iPod"
> "Sent from my iPhone"
>
> which can be written as,
> re.compile("Sent from my (iPhone|iPod)")
>
> now if I want to slightly to extend it as,
>
> "Taken from my iPod"
> "Taken from my iPhone"
>
> I am looking how can I use or in the beginning pattern?
>
> and the third phase if the intermediate phrase,
>
> "from my" if also differs or changes.
>
> In a nutshell I want to extract a particular group of phrases,
> where, the beginning and end pattern may alter like,
>
> (i) either from beginning Pattern B1 to end Pattern E1,
> (ii) or from beginning Pattern B1 to end Pattern E2,
> (iii) or from beginning Pattern B2 to end Pattern E2,

The only hints I will add to those given is that you need a) pattern for 
a word, and b) a way to 'anchor' the pattern to the beginning and ending 
of the string so it will only match the first and last words.

This is a pretty good re practice problem, so go and practice and 
experiment.  Expect to fail 20 times and you should beat your 
expectation ;-). The interactive interpreter, or Idle with its F5 Run 
editor window, makes experimenting easy and (for me) fun.

-- 
Terry Jan Reedy

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


Thread

Pattern Search Regular Expression subhabangalore@gmail.com - 2013-06-15 02:42 -0700
  Re: Pattern Search Regular Expression Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-15 10:05 +0000
    Re: Pattern Search Regular Expression Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-15 10:24 +0000
      Re: Pattern Search Regular Expression Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-15 11:55 +0100
        Re: Pattern Search Regular Expression rusi <rustompmody@gmail.com> - 2013-06-15 04:28 -0700
        Re: Pattern Search Regular Expression Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-15 13:41 +0000
          Re: Pattern Search Regular Expression Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-15 13:45 +0000
            Re: Pattern Search Regular Expression Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-15 15:28 +0100
              Re: Pattern Search Regular Expression subhabangalore@gmail.com - 2013-06-15 07:31 -0700
                Re: Pattern Search Regular Expression Andreas Perstinger <andipersti@gmail.com> - 2013-06-15 17:01 +0200
                Re: Pattern Search Regular Expression Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-15 16:04 +0100
                Re: Pattern Search Regular Expression subhabangalore@gmail.com - 2013-06-15 09:28 -0700
                Re: Pattern Search Regular Expression Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-15 17:39 +0100
                Re: Pattern Search Regular Expression Terry Reedy <tjreedy@udel.edu> - 2013-06-15 16:24 -0400
  Re: Pattern Search Regular Expression Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-15 11:18 +0100
  Re: Pattern Search Regular Expression rurpy@yahoo.com - 2013-06-15 09:59 -0700
  Re: Pattern Search Regular Expression subhabangalore@gmail.com - 2013-06-15 10:54 -0700
    Re: Pattern Search Regular Expression rurpy@yahoo.com - 2013-06-15 11:47 -0700
      Re: Pattern Search Regular Expression subhabangalore@gmail.com - 2013-06-15 12:38 -0700
      Re: Pattern Search Regular Expression rurpy@yahoo.com - 2013-06-15 13:41 -0700
  Re: Pattern Search Regular Expression Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-15 22:03 +0100
  Re: Pattern Search Regular Expression Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-15 22:26 +0100

csiph-web