>>> re.split(r'(\d+)', 'a1b2c30d40') ['a', '1', 'b', '2', 'c', '30', 'd', '40', '']
In the template: as stated in the comment, \d means "match one digit", + is a modifier that means "match one or more", therefore \d+ means "match as many digits as possible", This is placed in a group () , therefore, the entire template in the context of re.split means "split this line using as many digits as possible as a separator, additionally capturing the agreed separators in the result." If you omit the group, you will get ['a', 'b', 'c', 'd', ''] .
Cat plus plus
source share