Reputation: 16275
I need a regex for three words, seperated by spaces. I tried this:
>>>match = re.search('\w\s\w\s\w', 'cat dog mouse')
>>>match.group()
....
AttributeError: 'NoneType' object has no attribute 'group'
Shouldn't \w\s\w\s\w
accept "word word word"?
Upvotes: 0
Views: 60
Reputation: 189327
No, it only accepts words which are one letter long. You are probably looking for \w+
, and quite possibly the whole regex should be ^\s*\w+\s+\w+\s+\w+\s*$
with or without the optional surrounding whitespace \s*
.
Upvotes: 5