How to match anything except space and new line using Python regular expression?


The following code matches anything except space and new line in the given string using regex.

Example

import re
print re.match(r'^[^ \n]*$', """IfindTutorialspointuseful""")
print re.match(r'^[^ \n]*$', """I find Tutorialspointuseful""")
print re.match(r'^[^ \n]*$', """Ifind
Tutorialspointuseful""")

Output

This gives the output

<_sre.SRE_Match object at 0x00000000048965E0>
None
None

Updated on: 19-Feb-2020

811 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements