Group subprojects based on project name

how to group subprojects based on project.name

for e.g. if I have sub projects a/b/c a/b/c/d a/c/d b/e b/e/f

I want 2 sets

one with a/b/c a/b/c/d a/c/d

and one with

b/e b/e/f