I have strings that can have a various amount of "groups". I need to split them, but I am having trouble doing so. The groups will always start with [A-Z]{2-5} followed by a : and a string or varying length and spaces. It will always have a space in front of the group.
Example strings:
"YellowSky AA:Hello AB:1234 AC:1F 322 AD:hj21jkhjk23"
"Billy Bob Thorton AA:213231 AB:aaaa AC:ddddd 322 AD:hj2ffs dsfdsfd1jkhjk23"
My code thus far:
import re
D = "Test1 AA:Hello AB:1234 AC:1F 322 AD:hj21jkhjk23"
g = re.compile("(?<!^)\s+(?=[A-Z])(?!.\s)").split(D)
As you can see... this works for one word starting string, but not multiple words.


(?!^)\s+(?=[A-Z]+:), see regex101.com/r/QTmjkX/1split. Write a regexp that matches the groups, and usere.findall()