简体   繁体   English

python findall找不到正则表达式

[英]python findall not finding the regex

So I have a string: data = "1234 5678 9012 3456" and I have regex: (\\S)+ Which I confirmed matches "1234", "5678", "9012", "3456" with RegExr. 所以我有一个字符串: data = "1234 5678 9012 3456" ,我有正则表达式: (\\S)+我确认与RegExr匹配了"1234", "5678", "9012", "3456"

However when I do: re.findall("(\\S)+", data) it returns ["4", "8", "2", "6"] . 但是,当我这样做时: re.findall("(\\S)+", data)它返回["4", "8", "2", "6"] Am I using re.findall incorrectly to find "1234", "5678", "9012", "3456" ? 我是否使用re.findall错误地找到"1234", "5678", "9012", "3456"

The capturing group caused this: 捕获组导致以下情况:

re.findall("\S+", data)

works as expected. 如预期般运作。

No your regex is incorrect : 没有您的正则表达式不正确:

>>> re.findall("\S+", data)
['1234', '5678', '9012', '3456']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM