Weird problem matching with REs

Andrew Berg bahamutzero8825 at gmail.com
Sun May 29 10:35:19 EDT 2011


On 2011.05.29 09:18 AM, Steven D'Aprano wrote:
> >> What makes you think it shouldn't match?
> > 
> > AFAIK, dots aren't supposed to match carriage returns or any other
> > whitespace characters.
>
> They won't match *newlines* \n unless you pass the DOTALL flag, but they 
> do match whitespace:
>
> >>> re.search('abc.efg', '----abc efg----').group()
> 'abc efg'
> >>> re.search('abc.efg', '----abc\refg----').group()
> 'abc\refg'
> >>> re.search('abc.efg', '----abc\nefg----') is None
> True
I got things mixed up there (was thinking whitespace instead of
newlines), but I thought dots aren't supposed to match '\r' (carriage
return). Why is '\r' not considered a newline character?



More information about the Python-list mailing list