fork download
  1. import re
  2.  
  3. pattern = r"^\] prima 1 (?!\d+\b)\w+(?: (?!\d+\b)\w+)* 2 (?!\d+\b)\w+(?: (?!\d+\b)\w+)*$"
  4.  
  5. test_str = ("] prima 1 words 2 words\n"
  6. "] prima 1 9words 2 words\n"
  7. "] prima 1 words 2 words 3 words\n\n"
  8. "] prima 1 words another word that does not start with three or four 2 words that does not start with a number three or four\n"
  9. "] prima 1 words 2 words 4 words\n\n\n"
  10. "] prima 1 words 2 words\n"
  11. "] prima 1 2 2 1\n"
  12. "] prima 1 words 2 words 3 words")
  13.  
  14. regex = re.compile(pattern, re.MULTILINE)
  15. matches = regex.findall(test_str)
  16. print(matches)
Success #stdin #stdout 0.02s 9536KB
stdin
Standard input is empty
stdout
['] prima 1 words 2 words', '] prima 1 9words 2 words', '] prima 1 words another word that does not start with three or four 2 words that does not start with a number three or four', '] prima 1 words 2 words']