How can I remove hidden characters from a string? The row length in the database is different from the row in pythone. Most likely these are the characters \ t \ r \ n

  • For a regular expression, see the \S meta symbol. - And
  • 2
    re.sub ('[\ t \ r \ n]', '', text) - gil9red
  • one
    Strictly speaking, none of the \t \r \n characters is hidden and beautifully burned by its output behavior. Maybe you better print(repr(строка)) for each of your problem lines and show the result to us? - andreymal

1 answer 1

 text = ''' Hel lo Wor ld ! ''' print(repr(text)) # '\nHel\tlo \t\tWor\n\n\tld\t\n !\n' import re new_text = re.sub('[\t\r\n]', '', text) print(new_text) # Hello World!