I am looking for a regular expression that returns only three matching groups for the string " A: BC: D " where A, B, C, D are examples of words (\ w +) The following Python code prints unwanted (No, No).
I just want ("A", "No") ("No", "B") and "C", "D") using one regular expression (without adding python code to filter).
for m in re.compile(r'(?:(\w+)|)(?:(?::)(\w+)|)').finditer('A :BC:D'): print m.groups()
source share