[Tutor] finding special character string

Kent Johnson kent37 at tds.net
Sun Jun 1 13:25:29 CEST 2008

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)


More information about the Tutor mailing list