How to use loki |~ for regex search with case insensitive

Hi, I am setting up the metrics for Loki logs, so I can use {job=“abc”} !~ “error” to find any logs starts with error… But sometimes the log data can be Error, or ERROR, so how do I use this |~ operator to query the logs with case insensitive?

In regex, we can use /^data/i to make it case insensitive search, but this operator is using double quote “” and I tried to include /i, it didn’t work?

Can you please help?

1 Like

Hello @xz2000, the matching can be switched to case-insensitive prefixing the regex with (?i). So in your case it would be |~"(?i)error". You can find a lot of useful tips in LogQL docs.

4 Likes

Hello, this worked for me [eE][rR][rR][oO][rR] basically it means any combination of letters, one from every []. Apparently Grafana is based on the Go template which is not compatible with (?i) or /i flags.