+ 2
Why should \D mean 1 or more non-digits?
Why should \D mean 1 or more non-digits? I expected \D to mean just a SINGLE non-digit instead. Since \d means a digit, doesn't it make sense that its inverse, namely /D, means A non-digit? NOT multiple of them, just a SINGLE non-digit.
6 Antworten
+ 3
1 or more , it depend on follow by +?*
if + it means at least 1 or more
if * it means at least 0 or more
if ? it means don't care , can have one or more or none of it
+ 2
See this example.
import re
pattern = r"(\D+\d)"
match = re.match(pattern, "Hi 999!")
if match:
print("Match 1")
match = re.match(pattern, "1, 23, 456!")
if match:
print("Match 2")
match = re.match(pattern, " ! $?")
if match:
print("Match 3")
You can try rubning it. The output is Match1. This means \D matches non-digits while \d matches digits.
+ 2
\d means it is a digit [0-9] and \D is no digit [^0-9]
+ 1
You are correct. "\D" matches exactly one non-digit character, just as "\d" matches exactly one digit. As others have pointed out, if you want to match one _or_more_ non-digit characters, you have to add a "+" on the end of it, as in "\D+".
+ 1
\d matches digits i.e. 1,2,... even 1000000 and so on that's why it's inverse \D matches more than 1 non digits
+ 1
beauty1234, correction: ? means 0 or 1 times, but not more.