Regular Expression
Character types
\w
matches with any alphanumeric character
-
.
matches to all characters, including symbols
-
\d
matches to all single digits [0-9]
-
\s
matches to all single spaces
-
\.
matches to the period character
import re
re.findall("\w", "h32rb17")
import re
re.findall("\d", "h32rb17")
Quantify occurrences
+
symbol represents one or more occurrences of a specific character.
*
symbol represents zero, one, or more occurrences of a specific character.
\d{2}
instructs Python to return all matches of exactly two single digits
\d{1,3}
數字 1 - 3 位數
import re
re.findall("\d+", "h32rb17")
import re
re.findall("\d*", "h32rb17")
import re
re.findall("\d{2}", "h32rb17 k825t0m c2994eh")
import re
re.findall("\d{1,3}", "h32rb17 k825t0m c2994eh")