import re
name = "John"
input_sense_auxs = [
"These sound system are too many, I think John can help us, otherwise it will be waiting for a while longer" ,
"These sound system are too many but I know that John can help us, otherwise it will be waiting for a while longer" ,
"These sound system are too many but I know that John can help us. otherwise it will be waiting for a while longer" ,
"Do you know if John with the others could come this afternoon?" ,
"John can help us, otherwise it will be waiting for a while longer" ,
"Can you help us, otherwise it will be waiting for a while longer for John" ,
"sorry! can you help us? otherwise it will be waiting for a while longer for John" ]
regex_patron_m1 = fr'(?:^|[?!¿¡,;:([.])\s *(?:(\w +(?:\s +\w +)*)\s *)?{name}(?:\s *(\w +(?:\s +\w +)*))?\s *(?:$|[]?!,;:).])'
# r"\s*((?:\w\s*)+)\s*?" + name + r"\s*((?:\w\s*)+)\s*\??"
for input_sense_aux in input_sense_auxs:
print ( f'--- {input_sense_aux} ---' )
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 ( ) if something_1 else ""
something_2 = something_2.strip ( ) if something_2 else ""
print ( repr ( something_1) )
print ( repr ( something_2) )
aW1wb3J0IHJlCgpuYW1lID0gIkpvaG4iCgppbnB1dF9zZW5zZV9hdXhzID0gWwogICAgIlRoZXNlIHNvdW5kIHN5c3RlbSBhcmUgdG9vIG1hbnksIEkgdGhpbmsgSm9obiBjYW4gaGVscCB1cywgb3RoZXJ3aXNlIGl0IHdpbGwgYmUgd2FpdGluZyBmb3IgYSB3aGlsZSBsb25nZXIiLAogICAgIlRoZXNlIHNvdW5kIHN5c3RlbSBhcmUgdG9vIG1hbnkgYnV0IEkga25vdyB0aGF0IEpvaG4gY2FuIGhlbHAgdXMsIG90aGVyd2lzZSBpdCB3aWxsIGJlIHdhaXRpbmcgZm9yIGEgd2hpbGUgbG9uZ2VyIiwKICAgICJUaGVzZSBzb3VuZCBzeXN0ZW0gYXJlIHRvbyBtYW55IGJ1dCBJIGtub3cgdGhhdCBKb2huIGNhbi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oKICAgICAgICBzb21ldGhpbmdfMSA9IHNvbWV0aGluZ18xLnN0cmlwKCkgaWYgc29tZXRoaW5nXzEgZWxzZSAiIgogICAgICAgIHNvbWV0aGluZ18yID0gc29tZXRoaW5nXzIuc3RyaXAoKSBpZiBzb21ldGhpbmdfMiBlbHNlICIiCgogICAgICAgIHByaW50KHJlcHIoc29tZXRoaW5nXzEpKQogICAgICAgIHByaW50KHJlcHIoc29tZXRoaW5nXzIpKQ==
stdout
--- These sound system are too many, I think John can help us, otherwise it will be waiting for a while longer ---
'I think'
'can help us'
--- These sound system are too many but I know that John can help us, otherwise it will be waiting for a while longer ---
'These sound system are too many but I know that'
'can help us'
--- These sound system are too many but I know that John can help us. otherwise it will be waiting for a while longer ---
'These sound system are too many but I know that'
'can help us'
--- Do you know if John with the others could come this afternoon? ---
'Do you know if'
'with the others could come this afternoon'
--- John can help us, otherwise it will be waiting for a while longer ---
''
'can help us'
--- Can you help us, otherwise it will be waiting for a while longer for John ---
'otherwise it will be waiting for a while longer for'
''
--- sorry! can you help us? otherwise it will be waiting for a while longer for John ---
'otherwise it will be waiting for a while longer for'
''