[Tutor] finding special character string
Dinesh B Vadhia
dineshbvadhia at hotmail.com
Sun Jun 1 15:49:56 CEST 2008
Thank-you Kent - it works a treat!
----- Original Message -----
From: Kent Johnson
To: Dinesh B Vadhia
Cc: tutor at python.org
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
<dineshbvadhia at hotmail.com> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080601/8166e1e0/attachment.htm>
More information about the Tutor
mailing list