问题
I have Grafana 5.2 dashboards sourcing data from Prometheus.
I have some labels in a dashboard that seem to be in the format *.<domain> for e.g. *.google.com e.t.c however, this doesn't play with Grafana without some smart regex to ignore the first two characters.
I have the following regex (?<=^\*\.|^)[-a-zA-Z0-9._ ]+ which doesn't seem to work in Grafana but works in regex101. It should result in the label as google.com i.e. without the first two characters *..
Can someone please let me know what causes this ?
回答1:
According to Grafana documentation, you may capture the part of a regex to return that substring:
Filter and modify the options using a regex capture group to return part of the text: Regex:
/.*(01|02)/Result:
01 02
Hence, you may use
^(?:\*\.)?([-a-zA-Z0-9._ ]+)
^ ^
See the regex demo.
Here,
^- start of a string(?:\*\.)?- an optional (due to?quantifier that matches 1 or 0 sequences) non-capturing group that matches a*.substring (1 or 0 times)([-a-zA-Z0-9._ ]+)- a capturing group that matches 1+ ASCII letters, digits,-,.,_and space and places its matched value into Group 1 and returns it in Grafana as a result of a match.
来源:https://stackoverflow.com/questions/52363955/grafana-regex-to-ignore-the-asterisk-as-the-first-character-in-labels