Pattern Search Regular Expression
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Jun 15 06:05:01 EDT 2013
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?
--
Steven
More information about the Python-list
mailing list