Thank-you Kent - it works a treat!

----- Original Message ----- 
From: Kent Johnson 
To: Dinesh B Vadhia 
Cc: [email protected] 
Sent: Sunday, June 01, 2008 4:25 AM
Subject: Re: [Tutor] finding special character string


On Sun, Jun 1, 2008 at 6:48 AM, Dinesh B Vadhia
<[EMAIL PROTECTED]> wrote:
> A text document has special character strings defined as "." + "set of
> characters" + ".".  For example, ".sup." or ".quadbond." or ".degree." etc.
> The length of the characters between the opening "." and closing "." is
> variable.
>
> Assuming that you don't know beforehand all possible special character
> strings, how do you find all such character strings in the text document?

Assuming the strings are non-overlapping, i.e. the closing "." of one
string is not the opening "." of another, you can find them all with
  import re
  re.findall(r'\..*?\.', text)

Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to