Splunk Search

How do I extract using regex?

sphiwee
Contributor

i have below result, how can I do a regex to extract the fields, first being DateTime, username, Action, Entity

2022-11-21 15:44:13,ea186520,CREATED,USERSESSIONLOG

Labels (2)
Tags (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @sphiwee,

you can use the Field User Extractor to extract these fields without using regexes, cebause they are comma separated fields.

If you want to use a regex, you can use this:

 

| rex "^(?<DateTime>[^,]*),(?<username>[^,]*),(?<Action>[^,]*),(?<Entity>[^,]*)"

 

that you can test at https://regex101.com/r/KMPkSa/1

Ciao.

Giuseppe

0 Karma

yuanliu
SplunkTrust
SplunkTrust

It quite depends on how stable is the actual data format.  If all values have no comma in them as illustrated, you can simply do

| rex "(?<DateTime>[^,]+, *(?<username>[^,]+), *(?<Action>[^,]+), *(?<Entity>[^,]+)"
Tags (1)
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to July Tech Talks, Office Hours, and Webinars!

What are Community Office Hours?Community Office Hours is an interactive 60-minute Zoom series where ...

Updated Data Type Articles, Anniversary Celebrations, and More on Splunk Lantern

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

A Prelude to .conf25: Your Guide to Splunk University

Heading to Boston this September for .conf25? Get a jumpstart by arriving a few days early for Splunk ...