How to strip spaces/tabs/newlines using Python regular expression?

PythonServer Side ProgrammingProgramming

The following code strips the spaces/tabs/newlines from given string using Python regex

We use '\S' in regex which stands for all non-whitespace characters

Example

import re
print re.findall(r"[\S]","""I find
    Tutorialspoint useful""")

Output

This gives the output

['I', 'f', 'i', 'n', 'd', 'T', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's', 'p', 'o', 'i', 'n', 't', 'u', 's', 'e', 'f', 'u', 'l']

raja
Published on 10-Jan-2018 10:46:10
Advertisements