Splunk Search

REX-Field Extraction Issues with Special Characters

SplunkDash
Motivator

Hello,

I have following Sample Event.

Q17CNB_L_0__20210630-235755_5828.html@^@^2021/06/30@^@^23:57:55@^@^ Q17CNB @^@^

I have following REX command to extract ID and DateTime Fields from it

rex "(?<ID>.{6}).*?@\^@\^(?<DateTime>\d\d\d\d\/\d\d\/\d\d@\^@\^\d\d:\d\d:\d\d) 

 ID looked as expected, but I got DateTime Field as  "2021/06/30@^@^23:57:55" . Is there anyways, we can have DateTime Field like "2021/06/30 23:57:55"....without (@^@^) from this Event. Thank you so much, appreciate your support in these efforts.

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

SaltyHash123
Explorer

You could either replace the character with a space

something like

 

 

| eval dateField = replace(dateField,"@^", " ")

 

 

Maybe you'll have to escape ^ with \^

otherwise you could create a field for the date and one for the time and append them into a new field (most probably less performance)

View solution in original post

SaltyHash123
Explorer

You could either replace the character with a space

something like

 

 

| eval dateField = replace(dateField,"@^", " ")

 

 

Maybe you'll have to escape ^ with \^

otherwise you could create a field for the date and one for the time and append them into a new field (most probably less performance)

SplunkDash
Motivator

Thank you so much, appreciate your support.

I think your codes is working as expected. I just have done some tweaking based on your recommendation ......working as expected. Here is the final code:

| rex "(?<ID>.{6}).*?@\^@\^(?<DateTime>\d\d\d\d\/\d\d\/\d\d@\^@\^\d\d:\d\d:\d\d)"

| eval DateTime = replace(DateTime,"@\^@\^", " ")

 

Thank you again.

0 Karma

SaltyHash123
Explorer

I am glad it helped.  Btw you can optimize your regular expression

You could for example use \d{4} instead of \d\d\d\d . 

You can checkout a cheat sheet  like https://cheatography.com/davechild/cheat-sheets/regular-expressions/ for some useful commands 🙂

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...

Index This | How many sevens are there between 1 and 100?

August 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...