I have tried
re.findall(r'(\d\*\*\d)','3*2**3**2*5**4**')
The output is ['2**3', '5**4']
. My desired output is ['2**3','3**2', '5**4']
. What change is needed in re?
I have tried
re.findall(r'(\d\*\*\d)','3*2**3**2*5**4**')
The output is ['2**3', '5**4']
. My desired output is ['2**3','3**2', '5**4']
. What change is needed in re?
Change your regex to use a lookahead assertion which will not consume the string while matching:
import re
string = '3*2**3**2*5**4**'
print(re.findall(r'(?=(\d\*\*\d))', string))
>> ['2**3', '3**2', '5**4']