I’d like to extract the designator and ops from the string designator: op1 op2, in which there could be 0 or more ops and multiple spaces are allowed. I used the following regular expression in Python
import re
match = re.match(r"^(\w+):(\s+(\w+))*", "des1: op1 op2")
The problems is that only des1 and op2 is found in the matching groups, op1 is not. Does anyone know why?
The groups from above code is Group 0: des1: op1 op2 Group 1: des1 Group 2: op2 Group 3: op2
both are ‘found’, but only one can be ‘captured’ by the group. if you need to capture more than one group, then you need to use the regular expression functionality multiple times. You could do something like this, first by rewriting the main expression:
then you need to extract the individual subsections: