+ 13

Why does not "Match 2" and "E3" match in this code?

https://code.sololearn.com/csxUZgCdxIw9/?ref=app

24th Mar 2018, 11:01 PM
Vučko/Вучко/Vuchko
Vučko/Вучко/Vuchko - avatar
8 Réponses
+ 9
Your regular expression calls for two letters and then a number. E3 only has one letter
24th Mar 2018, 11:05 PM
Ariela
Ariela - avatar
+ 4
pattern = r"[A-Z]+[0-9]" will match both 1 + 2
5th May 2018, 9:44 AM
Johannes
Johannes - avatar
+ 1
Pattern is two uppercase character followed by one digit. Three chracter string. E3 does not have second uppercase character.
19th Jun 2021, 1:18 PM
Anuj Singh
Anuj Singh - avatar
+ 1
The sequence of the pattern is Uppercase > Uppercase > Number. Therefore Both 'E3' and '1ab' aren't obey the sequence.
24th Aug 2021, 3:06 PM
Maru Demamu
Maru Demamu - avatar
+ 1
r"[A-Z][A-Z][0-9]" matches strings with 2 UPPERCASE LETTERS then 1 NUMBER DIGIT. It would still match a string that has more than that, like "amogusSU5". But it won't match a string that has less than that, LIKE "E3". (Has a single uppercase letter instead of 2)
12th Sep 2021, 6:25 AM
Bobbersnucker
Bobbersnucker - avatar
+ 1
You code calls for an UPPERCASE followed by another UPPERCASE and finally a digit. 'E3' has only one UPPERCASE letter
19th Jan 2023, 4:54 PM
Kofi Asare Brako Jnr
0
pattern definites three lists. The first two contain the elements or items which are the alphabetical characters in uppercase and the last contains the digits from 0 to 9. That's why the output sould have two upper case letters at the beginning and followed by numbers.
16th Jun 2021, 7:31 PM
CHUN
0
Answer: The reason “March 2” and “E3 are not matching is that, the sequence of your regular expresion (r"[A-Z][A-Z][0-9]") calls for Uppercase letter [A-Z], Uppercase letter [A-Z], and numbers [0-9]. Therefore, the only condition that certifies the right order in this case is LS8 which is match 1. In a simplest form again is: Capital letter, Capital letter, and numbers. Like this: LS8. I hope this helps you to clear your doubt….
25th May 2022, 8:34 PM
Weamie Sonkarlay J Y