Back
How do I check if a string matches this pattern?
Uppercase letter, number(s), uppercase letter, number(s)...
Example, These would match:
A1B2B10L1C1N200J1
A1B2
B10L1
C1N200J1
These wouldn't ('^' points to the problem)
a1B2^A10B^AB400^
a1B2
^
A10B
AB400
To check if string matches pattern you can use the regular expression below is the code for the same:-
import repattern = re.compile("^([A-Z][0-9]+)+$")pattern.match(string)
import re
pattern = re.compile("^([A-Z][0-9]+)+$")
pattern.match(string)
To know more about this you can have a look at the following video:-
31k questions
32.8k answers
501 comments
693 users