Splunk Search

Regex for fields that may or not be filled?

mrgibbon
Contributor

Hey Guys, tricky one I came across.
I have to find and match on fields that may not be present.
So far I have this to find the fields when they exist:

"Source computer: (?P[^,]+) ,Source IP: (?P[^,]+)"

But it fails when the field is not filled and just looks like this:
"Source computer: " or "Source IP: ".
In fact the whole thing can look like this:
"Source computer: ,Source IP: ,"

How can I overcome this and maybe insert a "null" or "missing" string if the field is empty?
Ive tried with no success:
| fillnull value="missing" sourcecomputer
| fillnull value=NULL sourcecomputer

Anyone? Thanks in advance.

Tags (1)

mrgibbon
Contributor

Answered my own question, using * and not + at the end of the search.

Rob
Splunk Employee
Splunk Employee

You may want to try using an eval statement such as;

|eval sourcecomputer=if(sourcecomputer=="", "missing", sourcecomputer)

This will rewrite your field that has an empty value (not exactly NULL) and replace it with missing and otherwise replace it with whatever is already in the sourcecomputer field.

That will work for one value at a time, otherwise, you may want to use the sed mode to replace empty values in your raw string.

|rex field=_raw mode=sed "s/:\s,/:\smissing,/g"
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!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...