matching any number of any character
cfelling at iae.nl
Mon Aug 23 18:10:35 EDT 1999
Lyn A Headley <laheadle at boguscs.uchicago.edu> wrote:
> accomplish such a task. I thought this would work:
>>>> import regex
>>>> rx = regex.compile('\(.\|\n\)+')
you see, it just matched 3 characters, but...
here you are tricked by the semantics of a quantified grouping operator.
A quantified group only remembers the last match, and as your group only
matches a single character, 'c' it is:)
(( shouldn't this be documented in the re module? it has stung more people
> but I wanted 'abc'!
so you have to refer to the whole match (rx.group(0)) or get the
quantification inside a group. e.g.
>>> rx = regex.compile('\(\(.\|\n|)+\)')
More information about the Python-list