<?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 rex - multiple matches and using | in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/rex-multiple-matches-and-using/m-p/33565#M7141</link>
    <description>&lt;P&gt;I'm trying to run several field extractions using the rex command.  Here is a sample log format:&lt;/P&gt;

&lt;P&gt;ironportmail: Info: MID 42342 ICID 1234 From: &lt;A href="mailto:xyz@yyx.com"&gt;xyz@yyx.com&lt;/A&gt;&lt;BR /&gt;
ironportmail: Info: MID 42342 ICID 1234 To: &lt;A href="mailto:abc@def.com"&gt;abc@def.com&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I'd like to extract the MID, ICID, From and To fields using just one rex command.  (This is so I can wrap an eventtype around it.)&lt;/P&gt;

&lt;P&gt;Conceptually I'm looking for something like this, but havent been able to get it to work:&lt;/P&gt;

&lt;P&gt;rex field=_raw "MID (?&lt;MID&gt;[^ ]+)  |  ICID (?&lt;ICID&gt;[^ ]+)  |  From: &amp;lt;(?&lt;MAILFROM&gt;[^&amp;gt;]+)&amp;gt;  |  To: &amp;lt;(?&lt;MAILTO&gt;[^&amp;gt;]+)" &lt;/MAILTO&gt;&lt;/MAILFROM&gt;&lt;/ICID&gt;&lt;/MID&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Dec 2011 23:43:39 GMT</pubDate>
    <dc:creator>jshaynes</dc:creator>
    <dc:date>2011-12-12T23:43:39Z</dc:date>
    <item>
      <title>rex - multiple matches and using |</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-multiple-matches-and-using/m-p/33565#M7141</link>
      <description>&lt;P&gt;I'm trying to run several field extractions using the rex command.  Here is a sample log format:&lt;/P&gt;

&lt;P&gt;ironportmail: Info: MID 42342 ICID 1234 From: &lt;A href="mailto:xyz@yyx.com"&gt;xyz@yyx.com&lt;/A&gt;&lt;BR /&gt;
ironportmail: Info: MID 42342 ICID 1234 To: &lt;A href="mailto:abc@def.com"&gt;abc@def.com&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I'd like to extract the MID, ICID, From and To fields using just one rex command.  (This is so I can wrap an eventtype around it.)&lt;/P&gt;

&lt;P&gt;Conceptually I'm looking for something like this, but havent been able to get it to work:&lt;/P&gt;

&lt;P&gt;rex field=_raw "MID (?&lt;MID&gt;[^ ]+)  |  ICID (?&lt;ICID&gt;[^ ]+)  |  From: &amp;lt;(?&lt;MAILFROM&gt;[^&amp;gt;]+)&amp;gt;  |  To: &amp;lt;(?&lt;MAILTO&gt;[^&amp;gt;]+)" &lt;/MAILTO&gt;&lt;/MAILFROM&gt;&lt;/ICID&gt;&lt;/MID&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2011 23:43:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-multiple-matches-and-using/m-p/33565#M7141</guid>
      <dc:creator>jshaynes</dc:creator>
      <dc:date>2011-12-12T23:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: rex - multiple matches and using |</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-multiple-matches-and-using/m-p/33566#M7142</link>
      <description>&lt;P&gt;I think you'd be better off putting this in &lt;CODE&gt;props.conf&lt;/CODE&gt; / &lt;CODE&gt;transforms.conf&lt;/CODE&gt; instead so you won't have to specify your field extractions explicitly in each search that you want to use these fields.&lt;/P&gt;

&lt;P&gt;That said, this will work, though with a caveat:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=_raw max_match=10 "(?:MID (?&amp;lt;mid&amp;gt;[^ ]+)|ICID (?&amp;lt;icid&amp;gt;[^ ]+)|From: &amp;lt;(?&amp;lt;mailfrom&amp;gt;[^&amp;gt;]+)&amp;gt;|To: &amp;lt;(?&amp;lt;mailto&amp;gt;[^&amp;gt;]+))"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The caveat being that you will need to provide rex with a &lt;CODE&gt;max_match&lt;/CODE&gt; (default is 1), otherwise it will stop once it finds its first match.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2011 08:22:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-multiple-matches-and-using/m-p/33566#M7142</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2011-12-13T08:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: rex - multiple matches and using |</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-multiple-matches-and-using/m-p/33567#M7143</link>
      <description>&lt;P&gt;awesome, that did it.  thanks.&lt;/P&gt;

&lt;P&gt;the reason im running these inline is because I am searching off of a summary index.  those fields do already get extracted automatically for regular searches, but since the fields get dropped after doing a " | collect index=summary", im having to recreate them.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2011 18:44:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-multiple-matches-and-using/m-p/33567#M7143</guid>
      <dc:creator>jshaynes</dc:creator>
      <dc:date>2011-12-13T18:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: rex - multiple matches and using |</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-multiple-matches-and-using/m-p/33568#M7144</link>
      <description>&lt;P&gt;couple of follow up questions:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;what does the ?: at the beginning do.  the query seems to work fine without it&lt;/LI&gt;
&lt;LI&gt;any way to prevent all of the empty matches that get returned as a result of changing max_match?&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;ex, I get a bunch of empty mailfrom, mailto, etc. fields since they don't all occur on every line:&lt;/P&gt;

&lt;P&gt;sample field list from search results:&lt;BR /&gt;
 mailfrom="" |  mailfrom="" |  mailfrom="" |  mailfrom=""&lt;A href="mailto:abc@bvd.com"&gt;abc@bvd.com&lt;/A&gt;" | mailto="" | mailto="" | mailto="&lt;A href="mailto:xyz@abc.com"&gt;xyz@abc.com&lt;/A&gt;" | ... etc&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2011 18:51:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-multiple-matches-and-using/m-p/33568#M7144</guid>
      <dc:creator>jshaynes</dc:creator>
      <dc:date>2011-12-13T18:51:27Z</dc:date>
    </item>
  </channel>
</rss>

