pythonregexstringstring-matching

Check if string matches pattern


How do I check if a string matches the following pattern?

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

Example:


Solution

  • import re
    pattern = re.compile("^([A-Z][0-9]+)+$")
    pattern.match(string)