Hi, I'm having an issue with my regex.
I'm my search, I told SPL to search for the string ERROR but it's returning [ERROR]
Why?
index=bitbucket
("ERROR" OR "OutOfMemoryError" OR "DEADLINE_EXCEEDED" OR "SEVERE" OR "FATAL" OR "connection pool exhausted" OR "ServiceUnavailable")
| eval detected_keyword=case(
match(_raw,"(?-i)\bERROR\b"), "ERROR",
match(_raw,"OutOfMemoryError"),"OutOfMemoryError",
match(_raw,"DEADLINE_EXCEEDED"),"DEADLINE_EXCEEDED",
match(_raw,"SEVERE"),"SEVERE",
match(_raw,"FATAL"),"FATAL",
match(_raw,"connection pool exhausted"),"connection pool exhausted",
match(_raw,"ServiceUnavailable"),"ServiceUnavailable"
)
| table _time host index detected_keyword source _raw
Hi @hotrodbass
I think your search is behaving as designed. [ and ] are major breakers, so [ERROR] is indexed as the term ERROR and the base search matches it. Your regex also matches, because \b sits between [ and E (non-word to word character).
If you want to exclude the bracketed form you could try this:
| eval detected_keyword=case(
match(_raw,"(?-i)(?<![\[\w])ERROR(?![\]\w])"), "ERROR",
match(_raw,"OutOfMemoryError"), "OutOfMemoryError")The lookarounds reject ERROR when it's directly preceded by [ or a word character, or followed by ] or a word character. Events with only [ERROR] then get a null detected_keyword.
You could also add a " | where isnotnull(detected_keyword)" to drop them.
🌟 Did this answer help you? If so, please consider:
Your feedback encourages the volunteers in this community to continue contributing.
Hi @hotrodbass
I think your search is behaving as designed. [ and ] are major breakers, so [ERROR] is indexed as the term ERROR and the base search matches it. Your regex also matches, because \b sits between [ and E (non-word to word character).
If you want to exclude the bracketed form you could try this:
| eval detected_keyword=case(
match(_raw,"(?-i)(?<![\[\w])ERROR(?![\]\w])"), "ERROR",
match(_raw,"OutOfMemoryError"), "OutOfMemoryError")The lookarounds reject ERROR when it's directly preceded by [ or a word character, or followed by ] or a word character. Events with only [ERROR] then get a null detected_keyword.
You could also add a " | where isnotnull(detected_keyword)" to drop them.
🌟 Did this answer help you? If so, please consider:
Your feedback encourages the volunteers in this community to continue contributing.