You can use the look ahead feature offered by many regex engines. Basically, regex engines test a pattern without consuming it when looking to the future.
import re s = "u:sads asdas asdsad n:sadasda as:adds sdasd dasd a:sed eee" re.split(r'\s(?=[az]:)', s)
This means that it splits only when we have \s
followed by any letter and colon, but do not consume these tokens.
Sanjay T. Sharma
source share