
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to match a whitespace in python using Regular Expression?
The following code matches whitespaces in the given string.
Example
import re result = re.search(r'[\s]', 'The Indian Express') print result
output
<_sre.SRE_Match object at 0x0000000005106648>
Example
The following code finds all whitespaces in the given string and prints them
import re result = re.findall(r'[\s]', 'The Indian Express') print result
output
[' ', ' ']
- Related Articles
- How to match whitespace in python using regular expressions
- How to match a word in python using Regular Expression?
- How to match whitespace but not newlines using Python regular expressions?
- How to match a nonwhitespace character in python using Regular Expression?
- How to match a single character in python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- How to match parentheses in Python regular expression?
- How to match any one lowercase vowel in python using Regular Expression?
- How to match at the beginning of string in python using Regular Expression?
- How to match digits using Java Regular Expression (RegEx)
- PHP – Match regular expression using mb_ereg_match()
- How to match tab and newline but not space using Python regular expression?
- How to match anything except space and new line using Python regular expression?
- How to match nonword characters in Python using Regular Expression?\n\n\n\n
- How to match any one uppercase character in python using Regular Expression?\n\n

Advertisements