<?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 you write a regular expression to extract a field between two colons with a particular pattern? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-write-a-regular-expression-to-extract-a-field-between/m-p/446805#M126723</link>
    <description>&lt;P&gt;Your regex is not 100% correct.  It matches any text from a &lt;CODE&gt;space&lt;/CODE&gt; up to &lt;CODE&gt;:&lt;/CODE&gt;&lt;BR /&gt;
It will also give data from this line with only one &lt;CODE&gt;:&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sendmail[11111] w9234FKJa23233: to=xxxxxx
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So a more correct regex would be: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?::\s(?&amp;lt;extracted_field&amp;gt;[^\:]+)[\:])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will extract all data between two &lt;CODE&gt;:&lt;/CODE&gt;, except the first space.&lt;/P&gt;

&lt;P&gt;Also you do not need to escape the &lt;CODE&gt;:&lt;/CODE&gt; or put it in brackets at the end, so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?::\s(?&amp;lt;extracted_field&amp;gt;[^:]+):)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 29 Oct 2018 10:11:01 GMT</pubDate>
    <dc:creator>lakromani</dc:creator>
    <dc:date>2018-10-29T10:11:01Z</dc:date>
    <item>
      <title>How do you write a regular expression to extract a field between two colons with a particular pattern?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-write-a-regular-expression-to-extract-a-field-between/m-p/446802#M126720</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;Can anyone teach me how to write a regular expression to extract the field on the following raw event?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sendmail[11111]: w9234FKJa23233: to=xxxxxx
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to extract the "w9234FKJa23233" and create a new field that starts with "w" and then 13 char/digits.&lt;/P&gt;

&lt;P&gt;Thanks a lot&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 10:05:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-write-a-regular-expression-to-extract-a-field-between/m-p/446802#M126720</guid>
      <dc:creator>kcchu01</dc:creator>
      <dc:date>2018-10-26T10:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write a regular expression to extract a field between two colons with a particular pattern?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-write-a-regular-expression-to-extract-a-field-between/m-p/446803#M126721</link>
      <description>&lt;P&gt;Hi @kcchu01,&lt;/P&gt;

&lt;P&gt;Please try below regex, this will extract everything between &lt;CODE&gt;:&lt;/CODE&gt; and &lt;CODE&gt;:&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt; | rex field=_raw "(?:\s(?&amp;lt;extracted_field&amp;gt;[^\:]+)[\:])" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want results which only starts with &lt;CODE&gt;w&lt;/CODE&gt; then try below regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt; | rex field=_raw "(?:\s(?&amp;lt;extracted_field&amp;gt;w[^\:]+)[\:])" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Oct 2018 10:27:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-write-a-regular-expression-to-extract-a-field-between/m-p/446803#M126721</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-10-26T10:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write a regular expression to extract a field between two colons with a particular pattern?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-write-a-regular-expression-to-extract-a-field-between/m-p/446804#M126722</link>
      <description>&lt;P&gt;Thanks a lot, the field is extracted perfectly.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 09:39:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-write-a-regular-expression-to-extract-a-field-between/m-p/446804#M126722</guid>
      <dc:creator>kcchu01</dc:creator>
      <dc:date>2018-10-29T09:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write a regular expression to extract a field between two colons with a particular pattern?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-write-a-regular-expression-to-extract-a-field-between/m-p/446805#M126723</link>
      <description>&lt;P&gt;Your regex is not 100% correct.  It matches any text from a &lt;CODE&gt;space&lt;/CODE&gt; up to &lt;CODE&gt;:&lt;/CODE&gt;&lt;BR /&gt;
It will also give data from this line with only one &lt;CODE&gt;:&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sendmail[11111] w9234FKJa23233: to=xxxxxx
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So a more correct regex would be: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?::\s(?&amp;lt;extracted_field&amp;gt;[^\:]+)[\:])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will extract all data between two &lt;CODE&gt;:&lt;/CODE&gt;, except the first space.&lt;/P&gt;

&lt;P&gt;Also you do not need to escape the &lt;CODE&gt;:&lt;/CODE&gt; or put it in brackets at the end, so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?::\s(?&amp;lt;extracted_field&amp;gt;[^:]+):)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Oct 2018 10:11:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-write-a-regular-expression-to-extract-a-field-between/m-p/446805#M126723</guid>
      <dc:creator>lakromani</dc:creator>
      <dc:date>2018-10-29T10:11:01Z</dc:date>
    </item>
  </channel>
</rss>

