You can use re.findall here. You can extract Number between 'ID: number Name:.
s=" ID: 123 Name: Michael , ID: 124 Name: John "
re.findall(r'ID: (\d+) Name',s)
# ['123', '124']
Regex pattern explanation r'ID: (\d+) Name' You can read about regex Syntax
\d+ is used to capture numbers
() is used to capture the pattern enclosed between them.
re.findall Return a list of all non-overlapping matches in the string. If one or more capturing groups are present in the pattern, return
a list of groups; this will be a list of tuples if the pattern
has more than one group.
I would suggest using a dictionary instead of storing details in a string.
details={'123':'Micheal','124':'John'}
Since every ID would be unique you can use it a key and Name as value corresponding to the key.