From the strings in data, I'm trying to capture "FUND", respectively "FUND*", "Total", and "Rest" in a first group, the following thereafter floating point number, including its prefixed sign, in a second group, and the contents between the parenthesis or brackets in a third group with my regex pattern in Python 3.
import re
if __name__ == "__main__":
data = [
" - ♂️ FUND +145.00 [ 2 reached]",
" - FUND* +25.00 (⟶ Mar. 75.00/300)",
" - FUND +17.49 (⟶ Apr. 300.00)",
" - FUND +36.21 (⟶ May 250.00)",
" - FUND +150.00 (⟶ Jul. 1500.00)",
" - FUND +115.00 (⟶ Sep. 1000.00)",
" - ✒️ FUND +11.30",
" ----------------",
" Total 500.00",
" Rest 0.00"
]
pattern = r"(\w+)\s+([-+]?\d*\.?\d+)\s?([:\(\[].+[:\)\]])?"
for d in data:
match = re.match(pattern, d)
print(match)
I've tested the pattern on RegExr with the exact same data, and it works fine on the website. However, in Python match is always None?
Do I need to escape some characters in the pattern that I'm unaware of?
re.matchchecks if a string matches the regex from the beginning of the string, it does not search for the regex inside the string, so:The function you probably had in mind is
re.search: