简体   繁体   中英

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.

However when I do: re.findall("(\\S)+", data) it returns ["4", "8", "2", "6"] . Am I using re.findall incorrectly to find "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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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