Python Regex re.findall

By Xah Lee. Date: . Last updated: .
re.findall(regex, text)
Return a list of all non-overlapping matches of regex in text.
re.findall(regex, text, flags=flags)
With Flags .
import re
print(re.findall(r'@+', 'what   @@@do  @@you @think'))
# ['@@@', '@@', '@']

If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group.

import re
print(re.findall(r'( +)(@+)', 'what   @@@do  @@you @think'))
# [('   ', '@@@'), ('  ', '@@'), (' ', '@')]

Empty matches are included in the result unless they touch the beginning of another match.

import re
print(re.findall(r'\b', 'what   @@@do  @@you @think'))
# ['', '', '', '', '', '', '', '']

Python Regex Functions

Python Regular Expression