Splunk Enterprise

REGEX issue

hotrodbass
Explorer

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

 

Labels (1)
Tags (1)
0 Karma
1 Solution

livehybrid
SplunkTrust
SplunkTrust

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:

    • Adding karma to show it was useful
    • Marking it as the solution if it resolved your issue
    • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing.

View solution in original post

livehybrid
SplunkTrust
SplunkTrust

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:

    • Adding karma to show it was useful
    • Marking it as the solution if it resolved your issue
    • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing.

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

What You Read the Most in 2026: Splunk Lantern's Most Popular Articles, Top Themes, ...

Splunk Lantern is Splunk's customer success center that provides practical guidance from Splunk experts on key ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...

The Data Connection - November 2026

Machine data keeps growing, and every new source brings practical questions: where should it live, how ...