fork download
  1. import re
  2.  
  3. a = [
  4. "5 pounds cauliflower,",
  5. "cut into 1-inch florets (about 18 cups)",
  6. "2 large leeks,",
  7. "1 teaspoons salt",
  8. "3 cups of milk",
  9. "0 cups of milk",
  10. "1 cup of milk"
  11. ]
  12.  
  13. r = r"(\d+) +(cups?)\b"
  14.  
  15. def repl(m):
  16. x = int(m.group(1)) + 1
  17. return str(x) + " " + ("cup", "cups")[x > 1]
  18.  
  19. for s in a:
  20. print re.sub(r, repl, s)
Success #stdin #stdout 0.02s 6856KB
stdin
Standard input is empty
stdout
5 pounds cauliflower,
cut into 1-inch florets (about 19 cups)
2 large leeks,
1 teaspoons salt
4 cups of milk
1 cup of milk
2 cups of milk