fork download
  1. import re
  2. texts = [' 12345 = "Section 3 is ready for review"', ' 24680 = "Bob to review Chapter 4"']
  3. add = 'Complete: '
  4. key_words_list = ['Section', 'Page', 'Heading']
  5. pattern = re.compile(fr'^\s{{2}}[0-9]+\s=\s"(?!(?:{"|".join(key_words_list)})\b)')
  6. for text in texts:
  7. print(pattern.sub(fr'\g<0>{add}', text))
Success #stdin #stdout 0.02s 9696KB
stdin
Standard input is empty
stdout
  12345 = "Section 3 is ready for review"
  24680 = "Complete: Bob to review Chapter 4"