<?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 Why Does Regex Not Match Ampersand? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183235#M52766</link>
    <description>&lt;P&gt;I have an event field in the format of &lt;CODE&gt;fieldTitle=Type: This is a description&lt;/CODE&gt;.  Sometimes this event field contains an ampersand (&amp;amp;) in it, and when extracting the value of that field Splunk will stop and not pull the rest of the field.  For example:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;fieldTitle=Type: This &amp;amp; That&lt;/CODE&gt; Splunk will display the value of &lt;CODE&gt;fieldTitle&lt;/CODE&gt; as &lt;CODE&gt;This&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;In my regex I've tried escaping the ampersand, I've tried its hex and unicode equivalent values, and I've even tried a &lt;CODE&gt;.*&lt;/CODE&gt; which should match on everything regardless.  None of these result in a match beyond the ampersand.  &lt;/P&gt;

&lt;P&gt;I've also tried the field extraction tool, and aside from it generating a very long and static regex that isn't as dynamic as I need, it also does not work when I call it in a search.&lt;/P&gt;

&lt;P&gt;Has anyone had this same issue?  I'm on Splunk 6.2.&lt;/P&gt;</description>
    <pubDate>Thu, 07 May 2015 20:19:11 GMT</pubDate>
    <dc:creator>IngloriousSplun</dc:creator>
    <dc:date>2015-05-07T20:19:11Z</dc:date>
    <item>
      <title>Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183235#M52766</link>
      <description>&lt;P&gt;I have an event field in the format of &lt;CODE&gt;fieldTitle=Type: This is a description&lt;/CODE&gt;.  Sometimes this event field contains an ampersand (&amp;amp;) in it, and when extracting the value of that field Splunk will stop and not pull the rest of the field.  For example:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;fieldTitle=Type: This &amp;amp; That&lt;/CODE&gt; Splunk will display the value of &lt;CODE&gt;fieldTitle&lt;/CODE&gt; as &lt;CODE&gt;This&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;In my regex I've tried escaping the ampersand, I've tried its hex and unicode equivalent values, and I've even tried a &lt;CODE&gt;.*&lt;/CODE&gt; which should match on everything regardless.  None of these result in a match beyond the ampersand.  &lt;/P&gt;

&lt;P&gt;I've also tried the field extraction tool, and aside from it generating a very long and static regex that isn't as dynamic as I need, it also does not work when I call it in a search.&lt;/P&gt;

&lt;P&gt;Has anyone had this same issue?  I'm on Splunk 6.2.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 20:19:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183235#M52766</guid>
      <dc:creator>IngloriousSplun</dc:creator>
      <dc:date>2015-05-07T20:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183236#M52767</link>
      <description>&lt;P&gt;Can i get  your sample event?&lt;BR /&gt;
I think you can do someting like this:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|rex fields=_raw "fieldTitle\=Type\: (?&amp;lt;fieldname&amp;gt;[^\n])"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;depending of the end of your description. If not working, let me get your sample event.&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 21:04:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183236#M52767</guid>
      <dc:creator>stephanefotso</dc:creator>
      <dc:date>2015-05-07T21:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183237#M52768</link>
      <description>&lt;P&gt;Excellent moniker IngloriousSplunker!&lt;BR /&gt;
you need to show sample data and your regex. It's not Splunk stopping on the ampersand... it's your regex syntax and the event. the &amp;amp; isn't special in any way... &lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 22:24:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183237#M52768</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2015-05-07T22:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183238#M52769</link>
      <description>&lt;P&gt;It's sensor event data from another SIEM.  Below is a sample:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;May  7 2015 15:36:21 forwarding-system-hostname.domain.com 2015-05-07T15:36:21.201Z|ESM|CEF|358|McAfee NTR Incident start= 1430987152 end= 1430987152 rt=1430990752 deviceExternalId=Sensor-A eventId=1234 nitroNormId=123588 nitroObjectId=Malware: Botnet nitroBehavior=Botnet: GB Custom Signature C&amp;amp;C Traffic From DNS src=1.2.3.4 dst=5.6.7.8 nitroCat=Misc nitroDom=Domain
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above is a representation of the event I'm format I'm having an issue with.  The field I'm having an issue with is "nitroBehavior".  Splunk auto-parses the field, however, it extracts the value as "Botnet: Custom Signature C", and I've tried numerous regular expressions to include &lt;CODE&gt;| rex field=nitroBehavior "(?P&amp;amp;lt;fieldname&amp;amp;gt;.*)"&lt;/CODE&gt; and &lt;CODE&gt;|rex field=nitroBehavior "(?P&amp;amp;lt;fieldname&amp;amp;gt;[^nitro])"&lt;/CODE&gt; and other variations that should work, including using the hex and unicode representations of the ampersand.  Every time, it captures "Botnet: Custom Signature C", but never goes beyond the ampersand.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2015 02:28:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183238#M52769</guid>
      <dc:creator>IngloriousSplun</dc:creator>
      <dc:date>2015-05-08T02:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183239#M52770</link>
      <description>&lt;P&gt;I did not try &lt;CODE&gt;fields=_raw&lt;/CODE&gt; in the rex component, instead I designated &lt;CODE&gt;field=nitroBehavior&lt;/CODE&gt;, which is the field I wanted to perform the regex on.  I may try _raw tomorrow and just ignore everything up to the field I want to see if that changes the result any.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2015 02:31:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183239#M52770</guid>
      <dc:creator>IngloriousSplun</dc:creator>
      <dc:date>2015-05-08T02:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183240#M52771</link>
      <description>&lt;P&gt;It's a bit confusing as to what you want exactly in the new &lt;CODE&gt;fieldname&lt;/CODE&gt;because of your second example... but If the &lt;CODE&gt;src=&lt;/CODE&gt; field is always following the &lt;CODE&gt;nitroBehavior=&lt;/CODE&gt; field you can use this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;nitroBehavior=(?&amp;amp;lt;nitro&amp;amp;gt;.+)\ssrc&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Basically I think Splunk, when it automagically grabs the key value pairs (which it will do when it sees an &lt;CODE&gt;=&lt;/CODE&gt;) sees the ampersand as another delimiter and stops... so first, you want to re-assign the &lt;CODE&gt;nitroBehavior&lt;/CODE&gt; field (I called the field nitro above but you can call it nitroBehavior and it will take prescience over the auto assigned one.&lt;/P&gt;

&lt;P&gt;You can't use the field as is... since the text isn't surrounded by double quotes... and it's in a space delimited event (not nice 3rd party SIEM!) Splunk really just has to go with "best guess" and in this case, that's not good enough.&lt;/P&gt;

&lt;P&gt;So grab the &lt;CODE&gt;nitroBehavior&lt;/CODE&gt; field:&lt;BR /&gt;
&lt;CODE&gt;nitroBehavior=(?&amp;amp;lt;nitroBehavior&amp;amp;gt;.+)\ssrc&lt;/CODE&gt;&lt;BR /&gt;
And then you cay say &lt;BR /&gt;
&lt;CODE&gt;...|rex field=nitroBehavior "Botnet:\s(?&amp;amp;lt;botnet&amp;amp;gt;.+)\ssrc&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Or if that subfield is a pattern, you can grab it in transforms with a dynamic field name&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[nitroBehaviorInsides]
SOURCE_KEY = nitroBehavior #(the new one)
REGEX = (\w+):\s(.+)\ssrc
FORMAT $1::$2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That'll grab both key and value pair for all the different messages.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2015 04:51:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183240#M52771</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2015-05-08T04:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183241#M52772</link>
      <description>&lt;P&gt;I don't believe that field &lt;EM&gt;always&lt;/EM&gt; precedes a specific field, I've seen it at the very end of the alert before as well going back through my event data.  I will try the above regex, and perhaps provide more examples of variance in the events&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2015 12:49:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183241#M52772</guid>
      <dc:creator>IngloriousSplun</dc:creator>
      <dc:date>2015-05-08T12:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183242#M52773</link>
      <description>&lt;P&gt;With the above suggestion:&lt;/P&gt;

&lt;P&gt;I'm doing &lt;CODE&gt;|eval nitroBehavior=(?P&amp;amp;lt;nitroBehavior&amp;amp;gt;.+\ssrc&lt;/CODE&gt; and it's throwing an error saying "An unexpected character is reached at ?P&amp;lt;nitroBehavior&amp;gt;.+"&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2015 13:37:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183242#M52773</guid>
      <dc:creator>IngloriousSplun</dc:creator>
      <dc:date>2015-05-08T13:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183243#M52774</link>
      <description>&lt;P&gt;This regex &lt;CODE&gt;|rex field=_raw "(?:nitroBehavior=)(?&amp;amp;lt;behavior&amp;amp;gt;.+[^\ssrc])"&lt;/CODE&gt; captures the full value, but it does not stop at the next match of "src".  It prints: "Botnet: GB Custom Signature C&amp;amp;C Traffic From DNS src", and the same happens if I just do &lt;CODE&gt;|rex field=_raw "(?:nitroBehavior=)(?&amp;amp;lt;behavior&amp;amp;gt;.+\ssrc)"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2015 13:50:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183243#M52774</guid>
      <dc:creator>IngloriousSplun</dc:creator>
      <dc:date>2015-05-08T13:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why Does Regex Not Match Ampersand?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183244#M52775</link>
      <description>&lt;P&gt;This regular expression seems to have fixed it, however, it will not work if this field is at the end of the event.  In that case I could probably add a &lt;CODE&gt;\n&lt;/CODE&gt; match as well.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| rex field=_raw "(?:nitroBehavior=)(?&amp;amp;lt;behavior&amp;amp;gt;(.*?)(?=src))"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Thanks for the help and getting me on the right direction everyone.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2015 13:54:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-Does-Regex-Not-Match-Ampersand/m-p/183244#M52775</guid>
      <dc:creator>IngloriousSplun</dc:creator>
      <dc:date>2015-05-08T13:54:19Z</dc:date>
    </item>
  </channel>
</rss>

