+ 6

Why showing Match 2 while there 'A' is exists in 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") Output Match 1 Match 2

25th Jul 2019, 4:18 PM
Sanjay Soni
Sanjay Soni - avatar
2 Respuestas
+ 4
"pattern" tells that some match is found if some not-capital character is present: that's the case of Match1 and Match2. If you want to see all matching characters, you can use findall(): https://code.sololearn.com/c932mkueVaai/?ref=app
25th Jul 2019, 8:38 PM
Bilbo Baggins
Bilbo Baggins - avatar
+ 2
There are non-capital alphabets and numbers in the second option.
13th Aug 2019, 3:01 PM
Olaoluwa Sanya
Olaoluwa Sanya - avatar