import re
name = "John"
#In these examples it works fine
input_sense_aux = "These sound system are too many, I think John can help us, otherwise it will be waiting for a while longer"
#input_sense_aux = "These sound system are too many but I know that John can help us, otherwise it will be waiting for a while longer"
#input_sense_aux = "These sound system are too many but I know that John can help us. otherwise it will be waiting for a while longer"
#input_sense_aux = "Do you know if John with the others could come this afternoon?"
#In these examples it does not work well
#input_sense_aux = "John can help us, otherwise it will be waiting for a while longer"
#input_sense_aux = "Can you help us, otherwise it will be waiting for a while longer for John"
#input_sense_aux = "sorry! can you help us? otherwise it will be waiting for a while longer for John"
regex_patron_m1 = r"\s*((?:\w\s*)+)\s*?" + name + r"\s*((?:\w\s*)+)\s*\??"
m1 = re.search(regex_patron_m1, input_sense_aux, re.IGNORECASE) #Con esto valido la regex haber si entra o no en el bloque de code
if m1:
something_1, something_2 = m1.groups()
something_1 = something_1.strip()
something_2 = something_2.strip()
print(repr(something_1))
print(repr(something_2))
I need the regex to grab the content before "John" like this:
(start of sentence|¿|¡|,|;|:|(|[|.) \s* "content for something_1" \s* John
And then:
John \s* "content for something_2" \s* (end of sentence|?|!|,|;|:|)|]|.)
In the fists examples, the regex works fine:
'these teams are too many but I know that'
'can help us'
'Do you know if'
'with the others could come this afternoon'
But with the cases of the last 3 examples the regex does not return anything
And I need help to be able to generalize my regex to all these cases and at the same time respect the conditions in which it must extract the content of something_1 and something_2
For the 3 last examples, the expected results are:
''
' can help us'
' otherwise it will be waiting for a while longer for '
''
' otherwise it will be waiting for a while longer for '
''