Split name string given a character classification list

What’s a good way to solve this problem?

Suppose you’re given a name string that potentially may have multiple first, middle or last names. You want to return a list of first names, a list of last names and a list of middle names. You are also given a list with each index corresponding to the name string and at each index there is a classification for what type of name it is for example:

Assume ‘f’ is first name, ‘m’ is middle name, ‘l’ is last name and ‘s’ is separator. Then you get

“Bob Bob Dylan” as your string
with the class list as

Your return value should be [‘Bob’, ‘Bob’], [], [‘Dylan’]. The empty list because there was no middle names. What’s a good way to do this?