Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
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

Re: Pattern Search Regular Expression

2013-06-15 Thread Steven D'Aprano
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 .

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 10:42, subhabangal...@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

Re: Pattern Search Regular Expression

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 10:05:01 +, 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

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 11:24, Denis McMahon wrote: On Sat, 15 Jun 2013 10:05:01 +, 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

Re: Pattern Search Regular Expression

2013-06-15 Thread rusi
On Jun 15, 3:55 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: On 15/06/2013 11:24, Denis McMahon wrote: On Sat, 15 Jun 2013 10:05:01 +, Steven D'Aprano wrote: On Sat, 15 Jun 2013 02:42:55 -0700, subhabangalore wrote: Dear Group, I am trying to search the following

Re: Pattern Search Regular Expression

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 11:55:34 +0100, Mark Lawrence wrote: 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

Re: Pattern Search Regular Expression

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 13:41:21 +, Denis McMahon wrote: first_and_last = [sentence.split()[i] for i in (0, -1)] middle = sentence.split()[1:-2] Bugger! That last is actually: sentence.split()[1:-1] It just looks like a two. -- Denis McMahon, denismfmcma...@gmail.com --

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 14:45, Denis McMahon wrote: On Sat, 15 Jun 2013 13:41:21 +, Denis McMahon wrote: first_and_last = [sentence.split()[i] for i in (0, -1)] middle = sentence.split()[1:-2] Bugger! That last is actually: sentence.split()[1:-1] It just looks like a two. I've a very strong

Re: Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
On Saturday, June 15, 2013 7:58:44 PM UTC+5:30, Mark Lawrence wrote: On 15/06/2013 14:45, Denis McMahon wrote: On Sat, 15 Jun 2013 13:41:21 +, Denis McMahon wrote: first_and_last = [sentence.split()[i] for i in (0, -1)] middle = sentence.split()[1:-2] Bugger! That last

Re: Pattern Search Regular Expression

2013-06-15 Thread Andreas Perstinger
subhabangal...@gmail.com wrote: I know this solution but I want to have Regular Expression option. Just learning. http://mattgemmell.com/2008/12/08/what-have-you-tried/ Just spell out what you want: A word at the beginning, followed by any text, followed by a word at the end. Now look up the

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 15:31, subhabangal...@gmail.com wrote: Dear Group, I know this solution but I want to have Regular Expression option. Just learning. Regards, Subhabrata. Start here http://docs.python.org/2/library/re.html Would you also please read and action this,

Re: Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
On Saturday, June 15, 2013 8:34:59 PM UTC+5:30, Mark Lawrence wrote: On 15/06/2013 15:31, subhabangal...@gmail.com wrote: Dear Group, I know this solution but I want to have Regular Expression option. Just learning. Regards, Subhabrata. Start here

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 17:28, subhabangal...@gmail.com wrote: You've been pointed at several links, so what have you tried, and what, if anything, went wrong? Or do you simply not understand, in which case please say so and we'll help. I'm not trying to be awkward, it's simply known that you learn

Re: Pattern Search Regular Expression

2013-06-15 Thread rurpy
On 06/15/2013 03:42 AM, subhabangal...@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

Re: Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
On Saturday, June 15, 2013 3:12:55 PM UTC+5:30, subhaba...@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

Re: Pattern Search Regular Expression

2013-06-15 Thread rurpy
On Saturday, June 15, 2013 11:54:28 AM UTC-6, subhaba...@gmail.com wrote: Thank you for the answer. But I want to learn bit of interesting regular expression forms where may I? No Mark, thank you for your links but they were not sufficient. Links to the Python reference documentation are

Re: Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
On Sunday, June 16, 2013 12:17:18 AM UTC+5:30, ru...@yahoo.com wrote: On Saturday, June 15, 2013 11:54:28 AM UTC-6, subhaba...@gmail.com wrote: Thank you for the answer. But I want to learn bit of interesting regular expression forms where may I? No Mark, thank you for your links

Re: Pattern Search Regular Expression

2013-06-15 Thread Terry Reedy
On 6/15/2013 12:28 PM, subhabangal...@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

Re: Pattern Search Regular Expression

2013-06-15 Thread rurpy
Oops... On Saturday, June 15, 2013 12:47:18 PM UTC-6, ru...@yahoo.com wrote: Links to the Python reference documentation are useful for people just beginning with some aspect of Python; they are for people who already know Python and want to look up details. That was supposed to be: Links

Re: Pattern Search Regular Expression

2013-06-15 Thread Joshua Landau
On 15 June 2013 11:18, Mark Lawrence breamore...@yahoo.co.uk wrote: I tend to reach for string methods rather than an RE so will something like this suit you? c:\Users\Mark\MyPythontype a.py for s in (In the ocean, On the ocean, By the ocean, In this group,

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 22:03, Joshua Landau wrote: On 15 June 2013 11:18, Mark Lawrence breamore...@yahoo.co.uk wrote: I tend to reach for string methods rather than an RE so will something like this suit you? c:\Users\Mark\MyPythontype a.py for s in (In the ocean, On the ocean,