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


Groups > comp.lang.python > #48364

Re: Pattern Search Regular Expression

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Pattern Search Regular Expression
Date 2013-06-15 16:24 -0400
References (5 earlier) <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>
Newsgroups comp.lang.python
Message-ID <mailman.3404.1371327873.3114.python-list@python.org> (permalink)

Show all headers | 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