Splunk Search

How do you remove specific special characters from a field value?

RonWonkers
Path Finder

Hi, I have a field called "Employee_Email". This field contains the value:

["firstname.lastname@gmail.com"]

How do I remove the special characters [" and "]?

 

I tried: 

| eval test1 = replace (Employee_Email "[" , "")

 

But when I tried to remove either [ or " it gives me the following errors:

Error in 'EvalCommand': Regex: missing terminating ] for character class

Or:

Unbalanced quotes.

 

Is there a way to ignore the normal effect of [ and "?

Labels (6)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

You need to escape the square brackets and double quotes

| eval test1=replace(replace(Employee_Email,"\[\"",""),"\"\]","")

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

You need to escape the square brackets and double quotes

| eval test1=replace(replace(Employee_Email,"\[\"",""),"\"\]","")

RonWonkers
Path Finder

Tried this and it worked thanks

0 Karma

PickleRick
SplunkTrust
SplunkTrust

As an alternative you can use other functions

| eval trimmed_email=trim(Employee_Email,"\"[]")

or

| eval substr_email=substr(Employee_Email,3,len(Employee_Email)-4)

RonWonkers
Path Finder

This is indeed a nice alternative thank you!

0 Karma

RonWonkers
Path Finder

Edit:

I tried: 

| eval test1 = replace (Employee_Email, "[" , "")
0 Karma
Get Updates on the Splunk Community!

3 Ways to Make OpenTelemetry Even Better

My role as an Observability Specialist at Splunk provides me with the opportunity to work with customers of ...

What's New in Splunk Cloud Platform 9.2.2406?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2406 with many ...

Enterprise Security Content Update (ESCU) | New Releases

In August, the Splunk Threat Research Team had 3 releases of new security content via the Enterprise Security ...