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


Groups > comp.lang.python > #48280

Re: Pattern Search Regular Expression

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Pattern Search Regular Expression
Date 2013-06-15 11:18 +0100
References <afd6b280-3b64-467b-a2e1-2b36377cd13a@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3370.1371291495.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 15/06/2013 10:42, subhabangalore@gmail.com wrote:
> Dear Group,
>
> I am trying to search the following pattern in Python.
>
> I have following strings:
>
>   (i)"In the ocean"
>   (ii)"On the ocean"
>   (iii) "By the ocean"
>   (iv) "In this group"
>   (v) "In this group"
>   (vi) "By the new group"
>         .....
>
> I want to extract from the first word to the last word,
> where first word and last word are varying.
>
> I am looking to extract out:
>    (i) the
>    (ii) the
>    (iii) the
>    (iv) this
>    (v) this
>    (vi) the new
>        .....
>
> The problem may be handled by converting the string to list and then
> index of list.
>
> But I am thinking if I can use regular expression in Python.
>
> If any one of the esteemed members can help.
>
> Thanking you in Advance,
>
> Regards,
> Subhabrata
>

I tend to reach for string methods rather than an RE so will something 
like this suit you?

c:\Users\Mark\MyPython>type a.py
for s in ("In the ocean",
           "On the ocean",
           "By the ocean",
           "In this group",
           "In this group",
           "By the new group"):
     print(' '.join(s.split()[1:-1]))


c:\Users\Mark\MyPython>a
the
the
the
this
this
the new

-- 
"Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green." Snooker 
commentator 'Whispering' Ted Lowe.

Mark Lawrence

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