<?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: How do I write the regex to identify the sourceip that can be found in different locations in my logs? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-the-regex-to-identify-the-sourceip-that-can-be/m-p/214816#M62994</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw max_match=0 "(?&amp;lt;ip&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
| eval sourceIP = mvindex(ip, mvcount(ip)-1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is basically going to do the following:&lt;BR /&gt;
- Store all the IPs in your event in the ip multivalued field (even if there's only one match, it will be a multivalued field with one value only)&lt;BR /&gt;
- Retrieve the latest ip from the multivalued field and assign to sourceIP&lt;/P&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval raw = "1.1.1.1 This is my sourceip; 2.2.2.2 My source ip is 1.1.1.2"
| eval raw = split(raw, ";")
| mvexpand raw
| rex field=raw max_match=0 "(?&amp;lt;ip&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
| eval sourceIP = mvindex(ip, mvcount(ip)-1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output: see attached picture &lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/1480iE802D8805405E54B/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jun 2016 09:44:39 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-06-21T09:44:39Z</dc:date>
    <item>
      <title>How do I write the regex to identify the sourceip that can be found in different locations in my logs?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-the-regex-to-identify-the-sourceip-that-can-be/m-p/214814#M62992</link>
      <description>&lt;P&gt;I have logs like below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1.1.1.1 This is my sourceip
2.2.2.2 My source ip is 1.1.1.2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have a situation where in some events, my sourceip comes first in the line (AS in First EVENT), and other events, IPs come first, but this is not sourceip. Whatever comes after (in this case, 1.1.1.2) is my source ip. How to write a regex for this lookahead?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 06:46:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-the-regex-to-identify-the-sourceip-that-can-be/m-p/214814#M62992</guid>
      <dc:creator>splunkn</dc:creator>
      <dc:date>2016-06-21T06:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write the regex to identify the sourceip that can be found in different locations in my logs?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-the-regex-to-identify-the-sourceip-that-can-be/m-p/214815#M62993</link>
      <description>&lt;P&gt;You can use two different regex: &lt;BR /&gt;
for the first event: rex field=yourfield "^(?P(\d.){4})This is my sourceip"&lt;BR /&gt;
for the 2nd even: rex field=youfield ".*My source ip is\s(?P(\d.){3}\d)"&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 09:21:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-the-regex-to-identify-the-sourceip-that-can-be/m-p/214815#M62993</guid>
      <dc:creator>tgdvopab</dc:creator>
      <dc:date>2016-06-21T09:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write the regex to identify the sourceip that can be found in different locations in my logs?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-the-regex-to-identify-the-sourceip-that-can-be/m-p/214816#M62994</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw max_match=0 "(?&amp;lt;ip&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
| eval sourceIP = mvindex(ip, mvcount(ip)-1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is basically going to do the following:&lt;BR /&gt;
- Store all the IPs in your event in the ip multivalued field (even if there's only one match, it will be a multivalued field with one value only)&lt;BR /&gt;
- Retrieve the latest ip from the multivalued field and assign to sourceIP&lt;/P&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval raw = "1.1.1.1 This is my sourceip; 2.2.2.2 My source ip is 1.1.1.2"
| eval raw = split(raw, ";")
| mvexpand raw
| rex field=raw max_match=0 "(?&amp;lt;ip&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
| eval sourceIP = mvindex(ip, mvcount(ip)-1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output: see attached picture &lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/1480iE802D8805405E54B/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 09:44:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-the-regex-to-identify-the-sourceip-that-can-be/m-p/214816#M62994</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-06-21T09:44:39Z</dc:date>
    </item>
  </channel>
</rss>

