0
Usage of ^ in character class
Why is it matching 1st one? The characters are small letters and r"[^A-Z]"--Does this search for only 1st pattern in the string or the whole string? import re pattern = r"[^A-Z]" if re.search(pattern, "this is all quiet"): print("Match 1") if re.search(pattern, "AbCdEfG123"): print("Match 2") if re.search(pattern, "THISISALLSHOUTING"): print("Match 3")
1 Antwort
+ 1
When ^ is used as the first character inside a regex class it means that you are looking for any character except those within the class. Your regex matches to any character that is not a capitol letter A-Z. This is why the last search is the only one that doesn't return true.
https://docs.python.org/3/howto/regex.html