fork download
  1. import re
  2.  
  3. prefix_pattern = "PREFIX"
  4. postfix_pattern = "POSTFIX"
  5. shared_pattern = "[a-zA-z]*"
  6. test_pattern ="("+prefix_pattern+shared_pattern+")|("+shared_pattern+postfix_pattern+")$"
  7.  
  8. pattern = re.compile(test_pattern)
  9.  
  10. test = 'PREFIXabc123' # Match
  11. #test = 'abcPOSTFIX' # No match
  12.  
  13. x = re.match(pattern,test)
  14. if x:
  15. print(x.group())
  16. else:
  17. print("Not found")
Success #stdin #stdout 0s 23352KB
stdin
Standard input is empty
stdout
PREFIXabc