Q:

Reg ex returning extra match

I am trying to pick the text between item 3 to item 4a, if it is not able to find the item 4a then it should look for the item 5 to end the search.
Below reg ex(with group) is able to pick the correct values. However, it returns a tuple with the matched groups.
re.findall(r'item 3\D(.*?)(item 4a|item 5)',"item 3 first value item 4 foo item 4a and item 5 item 3 second value item 4a")

Output:
[('first value item 4 foo ', 'item 4a'), ('second value ', 'item 4a')]

Please suggest any better method to achieve this without using group.

A:

You can use non-capturing group with:
re.findall(r'item 3\D(.*?)(?:item 4a|item 5)',"item 3 first value item 4 foo item 4a and item 5 item 3 second value item 4a")

