<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to get the type extracted in regex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339223#M100586</link>
    <description>&lt;P&gt;PERFECT!  Many thanks!!!!&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2018 15:13:27 GMT</pubDate>
    <dc:creator>dbcase</dc:creator>
    <dc:date>2018-01-30T15:13:27Z</dc:date>
    <item>
      <title>How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339208#M100571</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have this data and I'm challenged (not hard to do) on how to get the type extracted.   On the first line type=Thermostat is what is needed and writing regex for that is easy.  The problem comes on the 2nd line where now type would be equal to "Zone" which is not what we are looking for.  The second line type would actually be zoneType=smoke.  Is there a way to do this in one regex?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"id":"1410210064975923625.0","name":"Thermostat","type":"Thermostat","timeStamp":1513238363397,"troubleName":"bootloadFail"}   
     {"id":"117.0","name":"Zone 5","type":"Zone","timeStamp":1517253504269,"troubleName":"senLowBat","zoneType":"smoke"}    
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 03:44:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339208#M100571</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T03:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339209#M100572</link>
      <description>&lt;P&gt;I have a regex that looks like this, the trouble is it still matches type=Zone.  I could filter out type=Zone post regex I guess but that seems inefficient.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(type|zoneType)...(?&amp;lt;dtype&amp;gt;\w+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 03:49:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339209#M100572</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T03:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339210#M100573</link>
      <description>&lt;P&gt;Hey try this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|rex field=_raw "name\":\"(?&amp;lt;Name&amp;gt;\w+)"|rex field=_raw "zoneType\":\"(?&amp;lt;Name1&amp;gt;\w+)"|eval Name=coalesce(Name1,Name)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:04:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339210#M100573</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-01-30T04:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339211#M100574</link>
      <description>&lt;P&gt;Attempt #2, nada&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?!"type":"Zone")(type|zoneType)...(?&amp;lt;dtype&amp;gt;\w+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:16:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339211#M100574</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T04:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339212#M100575</link>
      <description>&lt;P&gt;It is tough to write a regular expression for JSON or XML files, as the field names are built-in. Here are a couple of choices that might be easier than writing regexes:&lt;/P&gt;

&lt;P&gt;Option 1:&lt;/P&gt;

&lt;P&gt;Look at the great answer provided by &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/15147"&gt;@somesoni2&lt;/a&gt; here &lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/489517/what-is-the-best-approach-for-a-search-time-extrac.html" target="_blank"&gt;https://answers.splunk.com/answers/489517/what-is-the-best-approach-for-a-search-time-extrac.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Option 2:&lt;/P&gt;

&lt;P&gt;Copy a sample of the data onto a test box. Bring the data into Splunk using the Add Data wizard so that you can use the Data Preview. In the preview, choose "json_no_timestamp" for the sourcetype. Then click the Save As button next to the sourcetype name - and create your own sourcetype. For this example, name it "detector."  Tell Splunk where to save this sourcetype - this defines where you will find the resulting props.conf entries. For example, if you choose the app "Searching and Reporting," you will find your new sourcetype in SPLUNK_HOME/etc/apps/search/local/props.conf. It will be located in a stanza named "[detector]" Now, Splunk should be able to identify all the fields in your data properly.&lt;/P&gt;

&lt;P&gt;As long as you are in the Data Preview, you can open some of the menus on the left and tell Splunk where to find the timestamp, etc. These settings will also be stored in the "[detector]" stanza of props.conf. When you are happy with the results, copy the stanza into production.&lt;/P&gt;

&lt;P&gt;Option 3:&lt;BR /&gt;
Like option 2, but use "json" instead of "json_no_timestamp" for the base sourcetype. In some ways, this is the easiest method BUT: it creates "index time fields." This means that the data will take up more space on disk and may be slower to retrieve (how much disk and how much slower depends on the volume of data). So I would avoid this option in favor of the other ones.&lt;/P&gt;

&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:52:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339212#M100575</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2020-09-29T17:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339213#M100576</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Interesting approach, didn't think of doing it that way.  Unfortunately though I can't use the name, this particular one the name matches the type but other records the name could be Porch or Downstairs, or Jimmy's room.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:21:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339213#M100576</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T04:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339214#M100577</link>
      <description>&lt;P&gt;not sure does it works or not!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:29:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339214#M100577</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-01-30T04:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339215#M100578</link>
      <description>&lt;P&gt;Hi Iguinn,&lt;/P&gt;

&lt;P&gt;In this case the appearance is a bit deceiving, whereas the string I posted looks like JSON, the real raw data looks like this&lt;BR /&gt;
    {"analyticType":"CustomAnalytic","buildTarget":"blah","product":"blah","clientSessionId":"DXSGCPC-CEAJTMA","Properties":{"index":0,"args":["{\"id\":\"1123.0\",\"name\":\"Garage Door 2\",\"type\":\"Zone\",\"timeStamp\":1517014287452,\"troubleName\":\"sensCom\",\"zoneType\":\"door\"}"],"category":"Event"}}&lt;/P&gt;

&lt;P&gt;Ugly I know.....  Sadly I can't get the developer to change the format.  So Splunk shows it as JSON like but all the backslashes throws it off.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:29:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339215#M100578</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T04:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339216#M100579</link>
      <description>&lt;P&gt;Lets try this again&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"analyticType":"CustomAnalytic","buildTarget":"blah","product":"blah","clientSessionId":"DXSGCPC-CEAJTMA","Properties":{"index":0,"args":["{\"id\":\"1123.0\",\"name\":\"Garage Door 2\",\"type\":\"Zone\",\"timeStamp\":1517014287452,\"troubleName\":\"sensCom\",\"zoneType\":\"door\"}"],"category":"Event"}}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:30:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339216#M100579</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T04:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339217#M100580</link>
      <description>&lt;P&gt;Hi &lt;/P&gt;

&lt;P&gt;Sorry no, by using the name instead of the type, where I would expect Thermostat, sometimes I get Downstairs because the name is a user input description field where the type is the type of device.  They can match but often they don't&lt;/P&gt;

&lt;P&gt;Does that make sense?&lt;/P&gt;

&lt;P&gt;This query works, its just inefficient &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=wholesale_app CustomAnalytic Properties.index=0|rename Properties.args{} as pr |rex field=pr "(type|zoneType)...(?&amp;lt;dtype&amp;gt;\w+)"|where dtype!="Zone"|stats count by dtype
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:36:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339217#M100580</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T04:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339218#M100581</link>
      <description>&lt;P&gt;check that, the regex in that query doesn't work, grrrrrrr&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:40:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339218#M100581</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T04:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339219#M100582</link>
      <description>&lt;P&gt;now it works&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=wholesale_app CustomAnalytic Properties.index=0|rename Properties.args{} as pr |rex max_match=10 field=pr "(type|zoneType)...(?&amp;lt;dtype&amp;gt;\w+)"|stats count by dtype|where dtype!="Zone"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:44:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339219#M100582</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T04:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339220#M100583</link>
      <description>&lt;P&gt;ohh..my mistake you are expecting type and not name &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|rex field=_raw "type\":\"(?&amp;lt;dtype&amp;gt;\w+)"|rex field=_raw "zoneType\":\"(?&amp;lt;dtype1&amp;gt;\w+)"|eval dtype=coalesce(dtype1,dtype)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if I understood it correctly...&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 04:51:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339220#M100583</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-01-30T04:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339221#M100584</link>
      <description>&lt;P&gt;hey @dbcase&lt;/P&gt;

&lt;P&gt;Try this run anywhere search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"id\":\"1410210064975923625.0\",\"name\":\"Thermostat\",\"type\":\"Thermostat\",\"timeStamp\":1513238363397,\"troubleName\":\"bootloadFail\"}" 
| append 
    [| makeresults 
    | eval _raw="{\"id\":\"117.0\",\"name\":\"Zone 5\",\"type\":\"Zone\",\"timeStamp\":1517253504269,\"troubleName\":\"senLowBat\",\"zoneType\":\"smoke\"}"] 
| rex field=_raw max_match=0 "(zoneType|type)\":\"(?&amp;lt;dtype&amp;gt;\w+)" 
| mvexpand dtype 
| stats count by dtype 
| where dtype!="Zone"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 06:24:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339221#M100584</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-01-30T06:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339222#M100585</link>
      <description>&lt;P&gt;In @somesoni2 's answer, he gives a transform that will look for key-value pairs in the data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; REGEX = \"([^\"]+)\":\"([^\"]+)\" 
 FORMAT = $1::$2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is a heckuva regular expression, but Splunk interprets it as "for every data pair that is found, where the two values are surrounded by double-quotes and separated by a colon, take the first item as the field name and the second item as the field value. You could change his regular expression to add "and there could be an optional backslash in front of the double-quote" by changing the regular expression to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; REGEX = \"([^\"]+)\\?\":\\?\"([^\"]+)\\?\" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(I think!) Try it and see what happens. I like this better than the other regexes, because it can handle events that have different fields - it doesn't require that all events have the same fields or that the fields are named consistently; it just extracts what it finds in each event.&lt;/P&gt;

&lt;P&gt;The good thing is that field extractions happen at search time, so you can change them as often as you like without having to re-index the data...&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 06:25:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339222#M100585</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2018-01-30T06:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the type extracted in regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339223#M100586</link>
      <description>&lt;P&gt;PERFECT!  Many thanks!!!!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 15:13:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-type-extracted-in-regex/m-p/339223#M100586</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-30T15:13:27Z</dc:date>
    </item>
  </channel>
</rss>

