+ 13
Why does not "Match 2" and "E3" match in this code?
8 Respostas
+ 9
Your regular expression calls for two letters and then a number.
E3 only has one letter
+ 4
pattern = r"[A-Z]+[0-9]" will match both 1 + 2
+ 1
Pattern is two uppercase character followed by one digit. Three chracter string. E3 does not have second uppercase character.
+ 1
The sequence of the pattern is Uppercase > Uppercase > Number. Therefore Both 'E3' and '1ab' aren't obey the sequence.
+ 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)
+ 1
You code calls for an UPPERCASE followed by another UPPERCASE and finally a digit.
'E3' has only one UPPERCASE letter
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.
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….