Pau*_*ulo 16 python regex pattern-matching
我正在尝试匹配中间有空格的字符串和字母数字字符,如下所示:
test = django cms
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下模式进行匹配:
patter = '\s'
Run Code Online (Sandbox Code Playgroud)
遗憾的是,它只匹配空格,所以当在re对象中使用搜索方法找到匹配时,它只返回空格,而不是整个字符串,如何更改模式以便在找到匹配时返回整个字符串?
Hug*_*ell 39
import re
test = "this matches"
match = re.match('(\w+\s\w+)', test)
print match.groups()
Run Code Online (Sandbox Code Playgroud)
回报
('this matches',)
Run Code Online (Sandbox Code Playgroud)