how to match whitespace and alphanumeric characters in python how to match whitespace and alphanumeric characters in python python python

how to match whitespace and alphanumeric characters in python


import retest = "this matches"match = re.match('(\w+\s\w+)', test)print match.groups()

returns

('this matches',)


I case there are more than one space use the following regexp:

'([\w\s]+)'

example

In [3]: import reIn [4]: test = "this matches and this"   ...: match = re.match('([\w\s]+)', test)   ...: print match.groups()   ...: ('this matches and this',)