James Thiele schrieb:
> I was helping a guy at work with regular expressions and found
> something I didn't expect:
> 
> 
>>>>re.match('\d', '7').group()
> 
> '7'

'\d' is not recognized as a escape sequence by Python and therefore it
is left unchanged <http://docs.python.org/ref/strings.html> in the
string which is passed to re.match.

> 
>>>>re.match('\\d', '7').group()
> 
> '7'
> [...]

This is the correct version. The first backslash escapes the second one
and this version will work even if a future version of Python recognizes
   \d as an escape sequence.


Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to