I have the following line, and I'm trying to find the best practice to cancel it.
The solution should be somewhat flexible in that I get this input from the API, and I cannot be absolutely sure that the existing character structure ( \n unlike \r ) will always be the same.
'"If it ain\'t broke, don\'t fix it." \nWent in for a detailed car wash.\nThe attendants raved-up my engine when taking the car into the tunnel. NOTE: my car is...'
This regular expression looks like it should work:
text_excerpt = re.sub(r'[\s"\\]', ' ', raw_text_excerpt).strip()
I read that decode() can work (and be the best solution overall).
raw_text_excerpt.decode('string_unescape')
I tried something in this direction, and it did not work. Any suggestions? Is regex better here?
Ben
source share