fork download
  1. import re
  2. codes = ['XA1', 'CZZ', 'BT9', 'WFF']
  3. block = "(?:{})".format("|".join(codes))
  4. rex = re.compile( r"^(?!.*\b(\w+)\b.*\b\1\b){0}(?:;{0})*;?$".format(block) )
  5. print(rex)
  6.  
  7. strs = ['XA1', 'XA1;CZZ', 'XA1;BT9;WFF;', 'XA1;XA1;', 'XA1;something']
  8. for s in strs:
  9. if rex.match(s):
  10. print("{} - Valid!".format(s))
  11. else:
  12. print("{} - Invalid!".format(s))
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
re.compile('^(?!.*\\b(\\w+)\\b.*\\b\\1\\b)(?:XA1|CZZ|BT9|WFF)(?:;(?:XA1|CZZ|BT9|WFF))*;?$')
XA1 - Valid!
XA1;CZZ - Valid!
XA1;BT9;WFF; - Valid!
XA1;XA1; - Invalid!
XA1;something - Invalid!