<?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 Field Extraction not working, need usable rex expression in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Field-Extraction-not-working-need-usable-rex-expression/m-p/693617#M235974</link>
    <description>&lt;P&gt;I have a search that yields&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;message&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;journey::cook_client:&lt;/SPAN&gt; &lt;SPAN class=""&gt;fan:&lt;/SPAN&gt; &lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;auger:&lt;/SPAN&gt; &lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;glow_v:&lt;/SPAN&gt; &lt;SPAN class=""&gt;36&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;glow:&lt;/SPAN&gt; &lt;SPAN class=""&gt;false&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;fuel:&lt;/SPAN&gt; &lt;STRONG&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;cavity_temp:&lt;/SPAN&gt; &lt;SPAN class=""&gt;257&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to extract the bold value associated with fuel, the value can be any number 0-1000 Using the field extractor I have gotten an unusable rex result:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;rex message="^\{"\w+":\d+,"\w+_\w+":"[a-f0-9]+","\w+":"\w+_\w+","\w+_\w+":"\w+","\w+_\w+":"\w+","\w+":\{"\w+":"\w+","\w+":"\w+","\w+":\d+\.\d+,"\w+":\-\d+\.\d+,"\w+":"\w+"\},"\w+_\w+":"\w+","\w+":"\w+::\w+_\w+_\w+:\s+\w+:\s+\d+,\s+\w+:\s+\d+,\s+\w+_\w+:\s+\d+,\s+\w+:\s+\w+,\s+\w+:\s+(?P&amp;lt;fuel_level&amp;gt;\d+)"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;When trying to search with this, the next command does not work and my result yields:&amp;nbsp;&lt;EM&gt;Invalid search command 'a'&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Can someone give me usable rex to get the highlighted number in a field titled 'fuel_level'&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jul 2024 14:36:57 GMT</pubDate>
    <dc:creator>nkavouris</dc:creator>
    <dc:date>2024-07-17T14:36:57Z</dc:date>
    <item>
      <title>Field Extraction not working, need usable rex expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-Extraction-not-working-need-usable-rex-expression/m-p/693617#M235974</link>
      <description>&lt;P&gt;I have a search that yields&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;message&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;journey::cook_client:&lt;/SPAN&gt; &lt;SPAN class=""&gt;fan:&lt;/SPAN&gt; &lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;auger:&lt;/SPAN&gt; &lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;glow_v:&lt;/SPAN&gt; &lt;SPAN class=""&gt;36&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;glow:&lt;/SPAN&gt; &lt;SPAN class=""&gt;false&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;fuel:&lt;/SPAN&gt; &lt;STRONG&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class=""&gt;cavity_temp:&lt;/SPAN&gt; &lt;SPAN class=""&gt;257&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to extract the bold value associated with fuel, the value can be any number 0-1000 Using the field extractor I have gotten an unusable rex result:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;rex message="^\{"\w+":\d+,"\w+_\w+":"[a-f0-9]+","\w+":"\w+_\w+","\w+_\w+":"\w+","\w+_\w+":"\w+","\w+":\{"\w+":"\w+","\w+":"\w+","\w+":\d+\.\d+,"\w+":\-\d+\.\d+,"\w+":"\w+"\},"\w+_\w+":"\w+","\w+":"\w+::\w+_\w+_\w+:\s+\w+:\s+\d+,\s+\w+:\s+\d+,\s+\w+_\w+:\s+\d+,\s+\w+:\s+\w+,\s+\w+:\s+(?P&amp;lt;fuel_level&amp;gt;\d+)"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;When trying to search with this, the next command does not work and my result yields:&amp;nbsp;&lt;EM&gt;Invalid search command 'a'&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Can someone give me usable rex to get the highlighted number in a field titled 'fuel_level'&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 14:36:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-Extraction-not-working-need-usable-rex-expression/m-p/693617#M235974</guid>
      <dc:creator>nkavouris</dc:creator>
      <dc:date>2024-07-17T14:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Field Extraction not working, need usable rex expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-Extraction-not-working-need-usable-rex-expression/m-p/693625#M235975</link>
      <description>&lt;P&gt;Please illustrate full message. &amp;nbsp;The look of the fragment suggest your source is actually JSON, something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{"message":"journey::cook_client: fan: 0, auger: 0, glow_v: 36, glow: false, fuel: 0, cavity_temp: 257", "foo":"bar"}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this correct? &amp;nbsp;Using regex directly on structured data is strongly discouraged as any regex is doomed to be fragile.&lt;/P&gt;&lt;P&gt;If the JSON is raw event, Splunk would have already extracted a field called "message". &amp;nbsp;Start from this field instead. &amp;nbsp;This field also is structured as KV pairs. &amp;nbsp;Use &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Extract" target="_blank" rel="noopener"&gt;kv&lt;/A&gt; aka extract instead of regex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rename _raw as temp, message as _raw
| kv kvdelim=": " pairdelim=","
| rename _raw as message, temp as _raw
| fields fuel&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your sample data would have given&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;fuel&lt;/TD&gt;&lt;TD&gt;_raw&lt;/TD&gt;&lt;TD&gt;_time&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;{"message":"journey::cook_client: fan: 0, auger: 0, glow_v: 36, glow: false, fuel: 0, cavity_temp: 257", "foo":"bar"}&lt;/TD&gt;&lt;TD&gt;2024-07-17 09:06:35&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is an emulation for you to play with and compare with real data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw = "{\"message\":\"journey::cook_client: fan: 0, auger: 0, glow_v: 36, glow: false, fuel: 0, cavity_temp: 257\", \"foo\":\"bar\"}"
| spath
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 16:10:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-Extraction-not-working-need-usable-rex-expression/m-p/693625#M235975</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-07-17T16:10:20Z</dc:date>
    </item>
  </channel>
</rss>

