Can regular expressions contain variables?

node_disk_read_bytes_total{instance=“aaa_user1_aaa”}
node_disk_read_bytes_total{instance=“bbb_user2_bbb”}
node_disk_read_bytes_total{instance=“ccc_user3_ccc”}

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.
node_disk_read_bytes_total{instance=~".*_user1_.*"}

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
node_disk_read_bytes_total{instance=~".*_$user_.*"}

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.