Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - re.findall returns unwanted result

re.findall("(100|[0-9][0-9]|[0-9])%", "89%")

This returns only result [89] and I need to return the whole 89%. Any ideas how to do it please?

like image 755
Jakub Turcovsky Avatar asked Apr 16 '13 19:04

Jakub Turcovsky


1 Answers

>>> re.findall("(?:100|[0-9][0-9]|[0-9])%", "89%")
['89%']

When there are capture groups findall returns only the captured parts. Use ?: to prevent the parentheses from being a capture group.

like image 71
John Kugelman Avatar answered Oct 02 '22 11:10

John Kugelman