I'm trying to pull certain parts out of a string using various regexs on continuously changing data strings.
For example the two regex's below should be ONLY pulling: Example $00.00 and bla $00.00
data = "Maybe Example $00.00 test $00.00 bla $00.00 dasdsadasd"
pull1 = re.match(r'^(Example) (\D\w+\D\w+)', data)
pull2 = re.match(r'^(bla) (\D\w+\D\w+)', data)
Anyone know what I'm doing wrong?
Thanks in advance - Hyflex
If you want extract a partial string, use 'search' instead of 'match'. This code works fine:
data = "Maybe Example $00.00 test $00.00 bla $00.00 dasdsadasd"
pull1 = re.search(r'(Example) (\D\w+\D\w+)', data)
pull2 = re.search(r'(bla) (\D\w+\D\w+)', data)
print pull1.group(0)
print pull2.group(0)
I've removed '^' from your regex.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With