Can regular expressions contain variables?


I have above metric in prometheus and I want to query one of them in grafana, for example user1, I use the following expression, it can work.

But once I define a variable and add it to the regular expression, It can’t work, for example, define a variable “user” and set its value to user1, and then change expression to

So my question is can regular expressions contain variables? If not, what can you do about it?

Yes, regular expressions can contain variables. Use query inspector and check generated query syntax. Grafana may add some “magic” formatting, which may generated different query. You may need to use advance variable formatting to achieve proper query.