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?

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.

3 Likes