Dashboards & Visualizations

Regex not working

Deprasad
Path Finder

Trying to Pick domainType and domainName from below log using the below regex:

It works in regex101 but not in Splunk, it gives a blank column.

domainName - rex"(?:domainName\\\"\:\\\")(?<domainName>([a-zA-Z0-9-\.]+))" 
domainType - rex"(?:domainType\\\"\:\\\")(?<domainType>\w)"



"payload":"{\"domainType\":\"L\",\"modifiedBy\":\"\",\"relayHost\":\"\",\"rewriteDomain\":\"\",\"wildcardAccount\":\"\",\"domainName\":\"xxx.yyyyy.com\"}"},"encoding":null,"contentType":"application/json","responseCode":null}

 

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Rex in splunk requires more escaping for backslashes than regex101

 

| makeresults | eval _raw="\"payload\":\"{\\\"domainType\\\":\\\"L\\\",\\\"modifiedBy\\\":\\\"\\\",\\\"relayHost\\\":\\\"\\\",\\\"rewriteDomain\\\":\\\"\\\",\\\"wildcardAccount\\\":\\\"\\\",\\\"domainName\\\":\\\"xxx.yyyyy.com\\\"}\"},\"encoding\":null,\"contentType\":\"application/json\",\"responseCode\":null} "
| rex "(?:domainName\\\\\"\:\\\\\")(?<domainName>([a-zA-Z0-9-\.]+))"
| rex "(?:domainType\\\\\"\:\\\\\")(?<domainType>\w)"

 

View solution in original post

saravanan90
Contributor

Below may help you..

|makeresults | eval _raw="\"payload\":\"{\\\"domainType\\\":\\\"L\\\",\\\"modifiedBy\\\":\\\"\\\",\\\"relayHost\\\":\\\"\\\",\\\"rewriteDomain\\\":\\\"\\\",\\\"wildcardAccount\\\":\\\"\\\",\\\"domainName\\\":\\\"xxx.yyyyy.com\\\"}\"},\"encoding\":null,\"contentType\":\"application/json\",\"responseCode\":null}\"" | rex field=_raw "domainType\\\\\":\\\\\"(?<domainType>[^\\\\\"]+).+domainName\\\\\":\\\\\"(?<domainname>[^\\\\\"]+)"

-------------------------------------------------------------------------------------

An upvote would be appreciated if the above reply is useful to you.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Rex in splunk requires more escaping for backslashes than regex101

 

| makeresults | eval _raw="\"payload\":\"{\\\"domainType\\\":\\\"L\\\",\\\"modifiedBy\\\":\\\"\\\",\\\"relayHost\\\":\\\"\\\",\\\"rewriteDomain\\\":\\\"\\\",\\\"wildcardAccount\\\":\\\"\\\",\\\"domainName\\\":\\\"xxx.yyyyy.com\\\"}\"},\"encoding\":null,\"contentType\":\"application/json\",\"responseCode\":null} "
| rex "(?:domainName\\\\\"\:\\\\\")(?<domainName>([a-zA-Z0-9-\.]+))"
| rex "(?:domainType\\\\\"\:\\\\\")(?<domainType>\w)"

 

Deprasad
Path Finder

Thanks!! that's worked. 🙂

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Deprasad,

please try this:

| rex "domainType\":\"(?<domainType>[^\"]*).*domainName\":\"(?<domainName>[^\"]*)"

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

Ciao.

Giuseppe

0 Karma

Deprasad
Path Finder

Thanks!! The payload you used in the regex101 is not same as the provided.
Though it worked in Regex101, still faced the same issue with Splunk. Tried the solution suggested by @ITWhisperer and it worked.

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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