Regular Expression Groups - loop
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Tue Aug 7 04:05:19 EDT 2007
On Tue, 07 Aug 2007 00:44:49 -0700, shahargs wrote:
> I'm trying to write application which parse one page to sentences and
> then, check every group for few things.
>
> The code:
> rawstr = r"""([^.?!]+[.?!])"""
> regex=re.compile(rawstr)
> matchs=regex.search(document)
> document, is the text i parsing. I cheked it in Kodos, and everything
> worked well. but, i'm trying to write for loop which check every
> group.
>
> I tried:
> for group in matchs.groups():
> but then, it's check only the first group. and i tried:
There is only one group in your regular expression. I guess you are
confusing groups within one match with multiples matches in the text.
`re.search()` finds exactly one sentence. If you want all sentences use
`re.find_all()` or `re.find_iter()`.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list