Naming Counter reset per different prefix

Right now I’m naming the item by expression as below

When there’s new combination of the custom code, the naming counter just jump to 0 and restart
E.g.
001-ABCD-EFGH-0001
001-ABCD-EFGG-0001

Are there anyway to keep the counter going, ignoring the prefixes?
What I want :
001-ABCD-EFGH-0001
001-ABCD-EFGG-0002
003-BBBC-EFGG-0003

Thanks in advance!

Possible but using autoname method, so you have to write a code on the server side and apply the logic according to the scenario.