How to get prefixes from metric names to a variable

I have a metric app_version with prefix for a service like this: web_app_version and some other prefixed services metrics (api, mailer, notifier and so on).
How can I extract all the prefixes from *_app_version metric to a variable?
PS: store - prometheus