fork(2) download
  1. import re
  2. date_div = "Blah blah\nblah, Updated: Aug. 23, 2012 Blah blah Updated: Feb. 13, 2019"
  3. up_to_word = "Updated:"
  4. rx_to_first = r'^.*?{}'.format(re.escape(up_to_word))
  5. rx_to_last = r'^.*{}'.format(re.escape(up_to_word))
  6. print("Remove all up to the first occurrence of the word including it:")
  7. print(re.sub(rx_to_first, '', date_div, flags=re.DOTALL).strip())
  8. print("Remove all up to the last occurrence of the word including it:")
  9. print(re.sub(rx_to_last, '', date_div, flags=re.DOTALL).strip())
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
Remove all up to the first occurrence of the word including it:
Aug. 23, 2012 Blah blah Updated: Feb. 13, 2019
Remove all up to the last occurrence of the word including it:
Feb. 13, 2019