Remove all escape sequences from a string

See here for the original answer.

What you're looking for is the re.sub() method:

import re

l = ['S;V;iPad\r', 'C;M;mouse pad\r', 'C;C;code swarm\r', 'S;C;OrangeHighlighter']
l_new = [re.sub(r'\r', '', i) for i in l]
print(l_new)

This will remove all occurrences of the \r escape sequence.


Tags

  1. python (Private)
  2. regex (Private)
  3. stack-overflow (Private)
  4. answer (Private)