fork download
  1. import re
  2.  
  3. text = """"This is a quote"
  4. This is an end "partial-
  5. quote" Here is more text.
  6. This is an end "partial-
  7. quote w/o more text
  8. This is an "embedded" quote
  9.  
  10. "This is a quote"
  11. This is an end "partial-
  12. quote" Here is more text.
  13. This is an end "partial-
  14. quote w/o more text"
  15. This is an "embedded" quote"""
  16.  
  17. print re.sub(r""""[^"\n]+?\n[^"\n]+?(?:"|$)\s*""", "\n", text, flags=re.M)
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
"This is a quote"
This is an end 
Here is more text.
This is an end 
This is an "embedded" quote

"This is a quote"
This is an end 
Here is more text.
This is an end 
This is an "embedded" quote