I have to manage all the possible home automation commands that I say to my voice assistant, some examples can be:
- "accendi la luce in corridoio, spegni la luce in camera e imposta 20 in salotto"
- "accendi la luce in camera e cameretta, spegni la luce in corridoio"
- "accendi la luce in salotto"
With a single regular expression I must be able to subdivide each type of command:
- ("accendi la luce in corridoio, ", "spegni la luce in camera e ", "imposta 20 in salotto")
- ("accendi la luce in camera e cameretta, ", "spegni la luce in corridoio")
- ("accendi la luce in salotto")
Using the regular expression from my previous question modified for the use I have to make of it, I get:
>>> print(re.search(r'(accendi.+)(spegni.+)(imposta.+)', "accendi la luce in corridoio, spegni la luce in camera e imposta 20 in salotto").groups())  
('accendi la luce in corridoio, ', 'spegni la luce in camera e ', 'imposta 20 in salotto')
This is OK, but not for these other commands:
>>> print(re.search(r'(accendi.+)(spegni.+)(imposta.+)', "accendi la luce in camera e cameretta, spegni la luce in corridoio").groups())  
Traceback (most recent call last):  
  File "<stdin>", line 1, in <module>  
AttributeError: 'NoneType' object has no attribute 'groups'  
>>> print(re.search(r'(accendi.+)(spegni.+)(imposta.+)', "accendi la luce in salotto").groups())
Traceback (most recent call last):  
  File "<stdin>", line 1, in <module>  
AttributeError: 'NoneType' object has no attribute 'groups'  
 
     
    