[Python-de] Re: Python-de digest, Vol 1 #247 - 7 msgs

Carsten Tilch ctilch at gmx.de
Fri Oct 5 22:02:08 EDT 2001


import re

pattern    = re.compile('(\.|\!|\?)')
sample_text = """The quarrel is between our masters and us their men.
'Tis all one. I will show myself a tyrant. When I have fought
with the men, I will be cruel with the maids- I will cut off
their heads.
The heads of the maids?
Ay, the heads of the maids, or their maidenheads.
Take it in what sense thou wilt.
They must take it in sense that feel it.
Me they shall feel while I am able to stand; and 'tis known I
am a pretty piece of flesh.
Greg. 'Tis well thou art not fish; if thou hadst, thou hadst been
poor-John. Draw thy tool! Here comes two of the house of
Montagues."""

strCounter = 0
strStart   = 0
strEnd     = len(sample_text)

while strStart < strEnd:
    match = pattern.search(sample_text,strStart)
    if match:
        #print sample_text[strStart:match.end(0)]
        strStart  = match.end(0)       
        strCounter = strCounter + 1
    else:
        strStart = strEnd
print strCounter






More information about the Python-de mailing list