Getting Data In

regex to capture both fields as below

pavanbmishra
Path Finder

Hi SMEs,

Seeking help to capture below 2 strings (Only string1 & Only string1) as below in one regex

","category":"Only string1",

","category":"a1b2c3-Only string2",

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

ITWhisperer
SplunkTrust
SplunkTrust

Often helps to be clearer 😀 Will this work?

| rex "\"category\":\".*?(?<string>[^\-\"]+)\""

 

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@pavanbmishra 

Can you please try this?

YOUR_SEARCH
 | rex field=_raw "\"category\":\"(.*\-)?(?<category>.*)\""

 

My Sample Search :

| makeresults | eval raw="\",\"category\":\"thisissomethingineedtocapture\",|\",\"category\":\"a1b2c3-thisissomethingialsoneedtocapture\",|\",\"category\":\"Only string1\",|\",\"category\":\"a1b2c3-Only string2\"," | eval raw=split(raw,"|")|mvexpand raw | rename raw as _raw
| rename comment as "Upto Now is sample data only" | rex field=_raw "\"category\":\"(.*\-)?(?<category>.*)\""


 Thanks
KV
▄︻̷̿┻̿═━一

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

0 Karma

pavanbmishra
Path Finder

Let me be more clear here

","category":"thisissomethingineedtocapture",

","category":"a1b2c3-thisissomethingialsoneedtocapture",

Here thisissomethinginnedtocapture & thisissomethingialsoneedtocapture should come in regex value. These both are strings and doesn't have any numeric value.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Often helps to be clearer 😀 Will this work?

| rex "\"category\":\".*?(?<string>[^\-\"]+)\""

 

ITWhisperer
SplunkTrust
SplunkTrust
| rex "\"category\":\".*(?<string>Only string\d)\""
0 Karma
Get Updates on the Splunk Community!

The Payment Operations Wake-Up Call: Why Financial Institutions Can't Afford ...

The same scenario plays out across financial institutions daily. A payment system fails at 11:30 AM on a busy ...

Make Your Case: A Ready-to-Send Letter for Getting Approval to Attend .conf25

Hello Splunkers, Want to attend .conf25 in Boston this year but not sure how to convince your manager? We've ...

Community Spotlight: A Splunk Expert's Journey

In the world of data analytics, some journeys leave a lasting impact not only on the individual but on the ...