I'm currently working with regular expressions. I know how to retrieve the euro amount with a regex:
r'[+-]?(?:[0-9]*[,])?[0-9]+'
I also know how to retrieve the word with CAPITAL letters:
r'\b[A-Z]+(?:\s+[A-Z]+)*\b'
But I don't seem to get the following to work. Retrieve the words between the euro amount and the first WORD in Capital. For example, if I have the following sentence:
€10,95 Hello how are you doing? good or, bad? WORD
I want to retrieve: "Hello how are you doing? good or, bad?"
Any help is appreciated.
With your shown samples, please try following regex. Written and tested in Python3x.
import re
text = '€10,95 Hello how are you doing? good or, bad? WORD '
val=re.search(r'€\d+(?:,\d+)?\s*(.*?)(?=\s+[A-Z])', text)
print(val.group(1))
Hello how are you doing? good or, bad?
Online demo for above regex
Explanation: Adding detailed explanation for above regex.
€\d+ ##Matching € character following 1 or more digits here.
(?:,\d+)?\s* ##In a non-capturing group matching comma followed by 1 or more digits keeping it optional followed by 0 or more spaces.
(.*?) ##Creating 1st(and only) capturing group with lazy match here.
(?=\s+[A-Z]) ##Doing positive look ahead to make sure its followed by spaces then capital letters.
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