fork download
  1. import re
  2. pattern = r"[0-9]\s*(?:[+-][+-]|\*/)\s*[0-9]"
  3. strings = [
  4. 'This is test 1 -- 1',
  5. 'This is test 2',
  6. 'This is test 3+1',
  7. 'This is test 4 */4'
  8. ]
  9.  
  10. for s in strings:
  11. res = re.search(pattern, s)
  12. if not res:
  13. print("Valid: " + s)
  14.  
  15.  
  16.  
Success #stdin #stdout 0.02s 9352KB
stdin
Standard input is empty
stdout
Valid: This is test 2
Valid: This is test 3+1