Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in Python by (47.6k points)

How do I check if a string matches this pattern?

Uppercase letter, number(s), uppercase letter, number(s)...

Example, These would match:

A1B2

B10L1

C1N200J1

These wouldn't ('^' points to the problem)

a1B2

^

A10B

^

AB400

^

1 Answer

0 votes
by (106k points)
edited by

To check if string matches pattern you can use the regular expression below is the code for the same:-

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:-

Related questions

0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...