fork(2) download
  1. import re
  2.  
  3. text1 = "This has four words"
  4. text2 = "This has three"
  5.  
  6. # Let's say sentences with at least 4 words pass.
  7.  
  8. res1 = re.match(r'\s*\S+(?:\s+\S+){3,}', text1)
  9. res2 = re.match(r'\s*\S+(?:\s+\S+){3,}', text2)
  10.  
  11. if res1:
  12. print("text1 Pass match")
  13. else:
  14. print("text1 Fail match")
  15. if res2:
  16. print("text2 Pass match")
  17. else:
  18. print("text2 Fail match")
  19.  
  20. res3 = re.findall(r'\s*\S+(?:\s+\S+){3,}', text1)
  21. res4 = re.findall(r'\s*\S+(?:\s+\S+){3,}', text2)
  22.  
  23. if len(res3) > 0:
  24. print("text1 Pass findall")
  25. else:
  26. print("text1 Fail findall")
  27. if len(res4) > 0:
  28. print("text2 Pass findall")
  29. else:
  30. print("text2 Fail findall")
Success #stdin #stdout 0.1s 10088KB
stdin
Standard input is empty
stdout
text1 Pass match
text2 Fail match
text1 Pass findall
text2 Fail findall