Incrementing numbers dependent of prefix

I use “magic” placeholders for some of my documents like invoices.
For example: INV-{MONTH}-{YEAR}-{NUMBER}.
Or: INV-{CUSTOMER}-{NUMBER}
I would expect that the number starts at zero when a new month begins or for a unique customer. Instead the number just increments.

Is there a way to achieve this without changing the code?

Yes, for example I do this for invoices:

.YY..MM.-.####

The above will create the first invoice in August like:
2408-0001