<?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: regex help in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28254#M5563</link>
    <description>&lt;P&gt;Thanks! This works like a charm. As a follow up, how can I pull specific fields from the result. For example, if I only want it to return name='joe'. I tried eval, but it still returns all of it.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Feb 2013 19:19:10 GMT</pubDate>
    <dc:creator>dbautist</dc:creator>
    <dc:date>2013-02-12T19:19:10Z</dc:date>
    <item>
      <title>regex help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28251#M5560</link>
      <description>&lt;P&gt;I have the following log snippet with a JSON payload and I want to run a regex such that it extracts the JSON fields so I can display them in a table. &lt;/P&gt;

&lt;P&gt;input:&lt;/P&gt;

&lt;P&gt;id=1234, payload={"shippingAddress": [{"name": "bob","address": "123 a street, san francisco, ca"},{"name": "joe","address": "14 b ave, new york, ny"}]}&lt;/P&gt;

&lt;P&gt;output:&lt;/P&gt;

&lt;P&gt;name           address&lt;BR /&gt;
bob             123 a street, san francisco, ca&lt;BR /&gt;
joe              14 b ave, new york, ny&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2013 04:57:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28251#M5560</guid>
      <dc:creator>dbautist</dc:creator>
      <dc:date>2013-02-12T04:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: regex help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28252#M5561</link>
      <description>&lt;P&gt;You're better off using&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| spath input=payload
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;than regex'ing your way through JSON.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2013 09:33:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28252#M5561</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-02-12T09:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: regex help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28253#M5562</link>
      <description>&lt;P&gt;Although I agree with @martin_mueller, you could use rex to extract the fields, but it will be cumbersome, here is an example based on your snippet (please remove the ## marks that have been inserted due to the Splunk answers formatting):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|rex field=payload max_match=0 "\"name\":\s\"(?&amp;lt;##name&amp;gt;[^"]+)\",\"address\":\s\"(?&amp;lt;##address&amp;gt;[^"]+)\"" | table name address
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bear in mind that this rex statement will take multiple values in the payload string and create multi value fields which you might need to use with eval statements such as mvexpand depending on the table you are looking to generate.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2013 17:46:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28253#M5562</guid>
      <dc:creator>Rob</dc:creator>
      <dc:date>2013-02-12T17:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: regex help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28254#M5563</link>
      <description>&lt;P&gt;Thanks! This works like a charm. As a follow up, how can I pull specific fields from the result. For example, if I only want it to return name='joe'. I tried eval, but it still returns all of it.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2013 19:19:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28254#M5563</guid>
      <dc:creator>dbautist</dc:creator>
      <dc:date>2013-02-12T19:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: regex help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28255#M5564</link>
      <description>&lt;P&gt;On event level you can do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | spath input=payload | rename shippingAddress{}.name AS name shippingAddress{}.address AS address | where name=joe
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That'll only give you events where one value of name is joe.&lt;BR /&gt;
Within one even you can filter the two multi-values fields like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...  | spath input=payload | rename shippingAddress{}.name AS name shippingAddress{}.address AS address | eval mv_index = mvfind(name, "joe") | eval name = mvindex(name, mv_index) | eval address = mvindex(address, mv_index)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That'll remove value from the multi-valued field not belonging to joe.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2013 19:44:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/regex-help/m-p/28255#M5564</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-02-12T19:44:02Z</dc:date>
    </item>
  </channel>
</rss>

