3

I have tried

re.findall(r'(\d\*\*\d)','3*2**3**2*5**4**')

and the output is ['2**3', '5**4'] my desired output is ['2**3','3**2', '5**4'] what change is needed in in re

sandepp
  • 460
  • 2
  • 6
  • 14

1 Answers1

5

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']
DeepSpace
  • 72,713
  • 11
  • 96
  • 140