

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to strip spaces/tabs/newlines using Python regular expression?
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']
- Related Questions & Answers
- How to remove tabs and newlines using Python regular expression?
- How to check if text is “empty” (spaces, tabs, newlines) in Python?
- How to remove white spaces using Java Regular Expression (RegEx)
- How to match whitespace but not newlines using Python regular expressions?
- How to write a Regular Expression in JavaScript to remove spaces?
- How to expand tabs in string to multiple spaces in Python?
- How do i match just spaces and newlines with Python regex?
- How can I replace newlines with spaces in JavaScript?
- How to strip all spaces from a column in MySQL?
- How to match a word in python using Regular Expression?
- How to match nonword characters in Python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- How to extract numbers from text using Python regular expression?
- How to extract date from text using Python regular expression?
Advertisements