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


Groups > comp.lang.python > #48282

Re: Pattern Search Regular Expression

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'from:addr:yahoo.co.uk': 0.04; 'affected': 0.07; 'indices': 0.07; 'string': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sentence': 0.09; '"by': 0.16; '"in': 0.16; 'expression.': 0.16; 'help?': 0.16; 'integers,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Regular': 0.16; 'tuple': 0.16; 'typeerror:': 0.16; 'index': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'typing': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'words': 0.29; 'converting': 0.30; '"",': 0.31; '-0700,': 0.31; 'ball': 0.31; "d'aprano": 0.31; 'extract': 0.31; 'steven': 0.31; 'file': 0.32; 'handled': 0.32; 'regular': 0.32; '(most': 0.33; 'problem': 0.35; 'but': 0.35; 'next': 0.36; 'list': 0.37; 'list.': 0.37; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'black': 0.61; 'new': 0.61; 'first': 0.61; 'group,': 0.63; 'dear': 0.65; 'watching': 0.68; '.....': 0.78; 'subject:Search': 0.84; 'white,': 0.84; 'received:89': 0.85; '(i)': 0.91; '(ii)': 0.91; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Pattern Search Regular Expression
Date Sat, 15 Jun 2013 11:55:34 +0100
References <afd6b280-3b64-467b-a2e1-2b36377cd13a@googlegroups.com> <51bc3c4d$0$29997$c3e8da3$5496439d@news.astraweb.com> <kphfdr$su9$8@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-89-240-174-199.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
In-Reply-To <kphfdr$su9$8@dont-email.me>
X-Antivirus avast! (VPS 130614-2, 14/06/2013), Outbound message
X-Antivirus-Status Clean
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.3371.1371293740.3114.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371293740 news.xs4all.nl 15920 [2001:888:2000:d::a6]:59194
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48282

Show key headers only | View raw


On 15/06/2013 11:24, Denis McMahon wrote:
> On Sat, 15 Jun 2013 10:05:01 +0000, Steven D'Aprano wrote:
>
>> On Sat, 15 Jun 2013 02:42:55 -0700, subhabangalore 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.
>>
>> No need for a regular expression.
>>
>> py> sentence = "By the new group"
>> py> words = sentence.split()
>> py> words[1:-1]
>> ['the', 'new']
>>
>> Does that help?
>
> I thought OP wanted:
>
> words[words[0],words[-1]]
>
> But that might be just my caffeine deprived misinterpretation of his
> terminology.
>

 >>> sentence = "By the new group"
 >>> words = sentence.split()
 >>> words[words[0],words[-1]]
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not tuple

So why would the OP want a TypeError?  Or has caffeine deprivation 
affected your typing skills? :)

-- 
"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