Does "\d" in regex mean a digit? Does "\d" in regex mean a digit? python python

Does "\d" in regex mean a digit?


[0-9] is not always equivalent to \d. In python3, [0-9] matches only 0123456789 characters, while \d matches [0-9] and other digit characters, for example Eastern Arabic numerals ٠١٢٣٤٥٦٧٨٩.


\d matches any single digit in most regex grammar styles, including python.Regex Reference


In Python-style regex, \d matches any individual digit. If you're seeing something that doesn't seem to do that, please provide the full regex you're using, as opposed to just describing that one particular symbol.

>>> import re>>> re.match(r'\d', '3')<_sre.SRE_Match object at 0x02155B80>>>> re.match(r'\d', '2')<_sre.SRE_Match object at 0x02155BB8>>>> re.match(r'\d', '1')<_sre.SRE_Match object at 0x02155B80>