Why don't you use partition sop to apply group name by any expression. Off the top of my head, you could store your current group names in a new attribute and reapply them using partition sop.
Hi, Kuba, thanks for the suggestion, it works fine.
(well, I used group sop because I seems to me it's the most straight forward way to do the task and I thought it could accept this kind of pattern matching. Anyway, thanks a lot.)