Sam and Acme use a simple, pure form of regular expressions. If they had the counting operations, this would be a trivial task, but to add them would open the door to the enormous, ill-conceived complexity of (no longer) regular expressions as the open source community thinks of them.
So yes: use other tools, with my apologies. -rob