Does “\d” in regex mean a digit?

前端 未结 6 1376
天命终不由人
天命终不由人 2020-11-22 14:16

I found that in 123, \\d matches 1 and 3 but not 2. I was wondering if \\d matches a digit sati

6条回答
  •  天命终不由人
    2020-11-22 14:51

    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>
    

提交回复
热议问题