fork download
  1. import re
  2.  
  3. name = "John"
  4.  
  5. input_sense_auxs = [
  6. "These sound system are too many, I think John can help us, otherwise it will be waiting for a while longer",
  7. "These sound system are too many but I know that John can help us, otherwise it will be waiting for a while longer",
  8. "These sound system are too many but I know that John can help us. otherwise it will be waiting for a while longer",
  9. "Do you know if John with the others could come this afternoon?",
  10.  
  11. "John can help us, otherwise it will be waiting for a while longer",
  12. "Can you help us, otherwise it will be waiting for a while longer for John",
  13. "sorry! can you help us? otherwise it will be waiting for a while longer for John"]
  14.  
  15. regex_patron_m1 = fr'(?:^|[?!¿¡,;:([.])\s*(?:(\w+(?:\s+\w+)*)\s*)?{name}(?:\s*(\w+(?:\s+\w+)*))?\s*(?:$|[]?!,;:).])'
  16. # r"\s*((?:\w\s*)+)\s*?" + name + r"\s*((?:\w\s*)+)\s*\??"
  17. for input_sense_aux in input_sense_auxs:
  18. print(f'--- {input_sense_aux} ---')
  19. 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
  20. if m1:
  21. something_1, something_2 = m1.groups()
  22.  
  23. something_1 = something_1.strip() if something_1 else ""
  24. something_2 = something_2.strip() if something_2 else ""
  25.  
  26. print(repr(something_1))
  27. print(repr(something_2))
Success #stdin #stdout 0.03s 9492KB
stdin
Standard input is empty
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'
''