fork download
  1. import re
  2. text = "X4IitemX6Nabc123"
  3. rx1 = r'^X(\d+)'
  4. m1 = re.search(rx1, text)
  5. if m1:
  6. rx2 = fr'^X(?P<namelen>\d+)I(?P<name>.{{{m1.group(1)}}})X(?P<numlen>\d+)N(?P<num>.+)$'
  7. if re.search(rx2, text):
  8. print(text, '-> MATCH!')
  9. else:
  10. print(text, '-> FAIL!')
  11. else:
  12. print(text, '-> FAIL!')
Success #stdin #stdout 0.03s 9416KB
stdin
Standard input is empty
stdout
X4IitemX6Nabc123 -> MATCH!