<?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 set up in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59571#M14675</link>
    <description>&lt;P&gt;sourcetype="xml" | rex "&amp;lt;CommandId&amp;gt;(?&lt;COMMANDID&gt;\d+)&amp;lt;/CommandId&amp;gt;"&lt;/COMMANDID&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 24 May 2012 16:24:10 GMT</pubDate>
    <dc:creator>TheWzrdOz</dc:creator>
    <dc:date>2012-05-24T16:24:10Z</dc:date>
    <item>
      <title>Regex set up</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59569#M14673</link>
      <description>&lt;P&gt;Very much a noob here.  I've read (or tried to read!) the docs, I've watched the videos and still it's not doing what I thought it should.&lt;/P&gt;

&lt;P&gt;I have loaded my data into Splunk (an XML file) and did a rex on the data to find what I was looking for.  That worked fine.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="xml" | rex "&amp;lt;CommandId&amp;gt;(?&amp;lt;commandid&amp;gt;d+)&amp;lt;/CommandId&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I want to persist the data. I added this to my props.conf file (in Splunk\etc\system\local):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[xml]
REPORT-uploads = commandId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this to transforms.conf (same location):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[commandId]
REGEX=&amp;lt;CommandId&amp;gt;(?&amp;lt;commandId&amp;gt;d+)&amp;lt;/CommandId&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Did I do this correctly?&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2012 15:39:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59569#M14673</guid>
      <dc:creator>TheWzrdOz</dc:creator>
      <dc:date>2012-05-24T15:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Regex set up</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59570#M14674</link>
      <description>&lt;P&gt;Markdown is really screwing with the formatting of the text.  Not certain how to get around it, either!&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2012 15:39:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59570#M14674</guid>
      <dc:creator>TheWzrdOz</dc:creator>
      <dc:date>2012-05-24T15:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Regex set up</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59571#M14675</link>
      <description>&lt;P&gt;sourcetype="xml" | rex "&amp;lt;CommandId&amp;gt;(?&lt;COMMANDID&gt;\d+)&amp;lt;/CommandId&amp;gt;"&lt;/COMMANDID&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2012 16:24:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59571#M14675</guid>
      <dc:creator>TheWzrdOz</dc:creator>
      <dc:date>2012-05-24T16:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: Regex set up</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59572#M14676</link>
      <description>&lt;P&gt;[xml]&lt;/P&gt;

&lt;H2&gt;REPORT-uploads = commandId&lt;/H2&gt;

&lt;P&gt;[commandId]&lt;BR /&gt;
 REGEX = &amp;lt;CommandId&amp;gt;(?&lt;COMMANDID&gt;\d+)&amp;lt;/CommandId&amp;gt;&lt;BR /&gt;
 FORMAT = commandId::$1&lt;/COMMANDID&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2012 16:24:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59572#M14676</guid>
      <dc:creator>TheWzrdOz</dc:creator>
      <dc:date>2012-05-24T16:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Regex set up</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59573#M14677</link>
      <description>&lt;P&gt;So first, nicely done so far - but I think you are doing too much work!&lt;/P&gt;

&lt;P&gt;With Splunk, you can use the &lt;STRONG&gt;xmlkv&lt;/STRONG&gt; command and ask Splunk to do the parsing that you are doing by hand. The only issue is that xml parsing can be slow, so you should search first and then parse. For example, if you are looking for &lt;STRONG&gt;commandid=xyz27&lt;/STRONG&gt;, run this search string&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=xml CommandId xyz27 | 
xmlkv | 
search CommandId=xyz27 | 
whateveryouwant
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How this works:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;The first line searches for any events that have both the terms "CommandId" and "xyz27". This is not the same as searching for CommandId=xyz27 but it will eliminate a lot of events. This means fewer events to parse in the next step&lt;/LI&gt;
&lt;LI&gt;The xmlkv command will parse the remaining events. Anywhere it sees &lt;CODE&gt;&amp;lt;tag&amp;gt;value&amp;lt;/tag&amp;gt;&lt;/CODE&gt;, it will create a field named tag and set its value to "value". Voila, fields extracted!&lt;/LI&gt;
&lt;LI&gt;The next step actually tests for CommandId=xyz27, eliminating any events that do not match&lt;/LI&gt;
&lt;LI&gt;Finally, you get to do whatever you were ultimately trying to do (statistics, timechart, etc)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;If you are going to do this a lot, you might consider saving it as a macro, once you get it sorted out.&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2012 20:19:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59573#M14677</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-05-24T20:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Regex set up</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59574#M14678</link>
      <description>&lt;P&gt;Second answer: &lt;/P&gt;

&lt;P&gt;If you want a direct answer to your question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I think your regex is probably correct, although I would escape the &amp;lt; characters in the regex (making them \&amp;lt; ) because &amp;lt; by itself has a special meaning to regex.&lt;/P&gt;

&lt;P&gt;So if you want to continue with your original solution, try that and forget the &lt;CODE&gt;xmlkv&lt;/CODE&gt;&lt;BR /&gt;
But your syntax is a bit wrong, too, I think you need the following in transforms.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[commandId]
REGEX=\&amp;lt;CommandId&amp;gt;(d+)\&amp;lt;/CommandId&amp;gt;
FORMAT=commandid::$1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Yeah, the markdown gets screwy sometimes when you put in XML or HTML stuff...&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2012 20:32:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-set-up/m-p/59574#M14678</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-05-24T20:32:46Z</dc:date>
    </item>
  </channel>
</rss>

