How come the code below is not matching the space character?
import re
hasSpace = re.compile(' ')
string = 'hello world'
if(hasSpace.match(string)):
print("Found a space")
else:
print("No space")
I also tried using:
hasSpace = re.compile('\s')
but it's not matching either. I also tried to add an r to make the string raw, but same result.
Any clue why?
if ' ' in string:is all you need.matchbysearch