Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.028 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'python.': 0.02; 'from:addr:yahoo.co.uk': 0.04; '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; '"by': 0.16; '"in': 0.16; 'a.py': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Regular': 0.16; 'index': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'help.': 0.21; 'header:User-Agent:1': 0.23; 'tend': 0.24; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'converting': 0.30; 'you?': 0.31; 'ball': 0.31; 'extract': 0.31; 'handled': 0.32; 'regular': 0.32; 'problem': 0.35; 'something': 0.35; 'but': 0.35; 'next': 0.36; 'list': 0.37; 'list.': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'expression': 0.60; 'black': 0.61; 'new': 0.61; 'first': 0.61; 'reach': 0.63; 'email addr:gmail.com': 0.63; 'group,': 0.63; 'dear': 0.65; 'watching': 0.68; '.....': 0.78; 'subject:Search': 0.84; 'thanking': 0.84; 'white,': 0.84; 'received:89': 0.85; '(i)': 0.91; '(ii)': 0.91; 'esteemed': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Pattern Search Regular Expression Date: Sat, 15 Jun 2013 11:18:10 +0100 References: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371291495 news.xs4all.nl 15971 [2001:888:2000:d::a6]:46309 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48280 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