+ 1
exclusion in character classes
Why doesn't ^ in the beginning of pattern = r"[^A-Z]" exclude the uppercase letters in re.search(pattern, "AbCdEfG123")?
4 Answers
+ 3
Can you please display the link of your code?
+ 2
try the carat on the outside of the square bracket
+ 2
my mistake youre pattern works.
https://code.sololearn.com/c7hye0QRvTln/?ref=app
0
here is the code:
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")
Result:
Match 1
Match 2