Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #48282
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: Pattern Search Regular Expression |
| Date | 2013-06-15 11:55 +0100 |
| References | <afd6b280-3b64-467b-a2e1-2b36377cd13a@googlegroups.com> <51bc3c4d$0$29997$c3e8da3$5496439d@news.astraweb.com> <kphfdr$su9$8@dont-email.me> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3371.1371293740.3114.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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