Letter-Match

Sun 29 June 2025
import re
contents = [
    "AB23",
    "A2B3", 
    "DE09",
    "MN90",
    "XYi9",
    "XY90"
]
for content in contents:
    regex_pattern = "(?:AB|DE|XY)\d+" 
    # starts with AB or DE; should contain one or more number

    m = re.match(regex_pattern, content)

    if(m):
        print('matched : '+content)
matched : AB23
matched : DE09
matched : XY90


<>:2: SyntaxWarning: invalid escape sequence '\d'
<>:2: SyntaxWarning: invalid escape sequence '\d'
C:\Users\Afia Jahan\AppData\Local\Temp\ipykernel_75024\3010093568.py:2: SyntaxWarning: invalid escape sequence '\d'
  regex_pattern = "(?:AB|DE|XY)\d+"


Score: 0

Category: basics