<?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 How to write regex to extract a field's values and pass them to a new field using rex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198899#M57554</link>
    <description>&lt;P&gt;How can I use the value from a field named &lt;CODE&gt;geog&lt;/CODE&gt; in the regular expression passed to the &lt;CODE&gt;rex&lt;/CODE&gt; command? In the example below, I'd like &lt;CODE&gt;foo&lt;/CODE&gt; to be substitued by whatever value &lt;CODE&gt;geog&lt;/CODE&gt; has.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=_raw "foo:(?&amp;lt;area&amp;gt;[^&amp;amp;]*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Sep 2014 07:40:35 GMT</pubDate>
    <dc:creator>johntopley</dc:creator>
    <dc:date>2014-09-01T07:40:35Z</dc:date>
    <item>
      <title>How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198899#M57554</link>
      <description>&lt;P&gt;How can I use the value from a field named &lt;CODE&gt;geog&lt;/CODE&gt; in the regular expression passed to the &lt;CODE&gt;rex&lt;/CODE&gt; command? In the example below, I'd like &lt;CODE&gt;foo&lt;/CODE&gt; to be substitued by whatever value &lt;CODE&gt;geog&lt;/CODE&gt; has.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=_raw "foo:(?&amp;lt;area&amp;gt;[^&amp;amp;]*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Sep 2014 07:40:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198899#M57554</guid>
      <dc:creator>johntopley</dc:creator>
      <dc:date>2014-09-01T07:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198900#M57555</link>
      <description>&lt;P&gt;By "it will only be one value" do you mean that it is static text? Because then you would just use the text...&lt;/P&gt;</description>
      <pubDate>Mon, 01 Sep 2014 08:31:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198900#M57555</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2014-09-01T08:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198901#M57556</link>
      <description>&lt;P&gt;No, it's not static text. It's a field value. I've edited by question accordingly.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Sep 2014 08:46:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198901#M57556</guid>
      <dc:creator>johntopley</dc:creator>
      <dc:date>2014-09-01T08:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198902#M57557</link>
      <description>&lt;P&gt;... | eval foo = geog | &lt;/P&gt;

&lt;P&gt;gives the value of the field &lt;CODE&gt;geog&lt;/CODE&gt; to the field &lt;CODE&gt;foo&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Somehow, I think that this is not what you're after. Please provide some sample events, your search, and your desired outcome.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2014 09:02:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198902#M57557</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2014-09-02T09:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198903#M57558</link>
      <description>&lt;P&gt;You are on the right track I think  - just replace | rex field=_raw with | rex field=geog.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2014 09:55:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198903#M57558</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2014-09-02T09:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198904#M57559</link>
      <description>&lt;P&gt;No, &lt;CODE&gt;geog&lt;/CODE&gt; is not the field I want rex to extract the information from. I just want to dynamically build up my rex regular expression to use whatever value the &lt;CODE&gt;geog&lt;/CODE&gt; field has rather than hard-coding a value in the regex.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2014 10:03:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198904#M57559</guid>
      <dc:creator>johntopley</dc:creator>
      <dc:date>2014-09-02T10:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198905#M57560</link>
      <description>&lt;P&gt;I'm confused - you want to use the value in the geog field but geog is not the field you want to extract the information from? Can you post an example? You can can have multiple capturing groups in a single rex command or have multiple rex commands. For example | rex field=geog "(?&lt;FOO&gt;[^:]+):(?&lt;MAP&gt;&lt;AREA /&gt;[^&amp;amp;]*)" | stats values(area) by foo&lt;/MAP&gt;&lt;/FOO&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2014 10:16:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198905#M57560</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2014-09-02T10:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198906#M57561</link>
      <description>&lt;P&gt;It's a URL query string like this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;querystring=geog:2011WARDH&amp;amp;totals:false&amp;amp;dm/2011WARDH:E06000016,E12000004,E06000016&amp;amp;etc...&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;geog&lt;/CODE&gt; field is extracted and returns &lt;CODE&gt;2011WARDH&lt;/CODE&gt; in this example. I want to extract &lt;CODE&gt;E06000016,E12000004,E06000016&lt;/CODE&gt; into a new &lt;CODE&gt;area&lt;/CODE&gt; field. As you can see, they're prefixed with the &lt;CODE&gt;2011WARDH&lt;/CODE&gt; value from the &lt;CODE&gt;geog&lt;/CODE&gt; field. This is not a fixed value, so I need it to vary within the regular expression as it varies within the &lt;CODE&gt;geog&lt;/CODE&gt; field.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2014 11:21:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198906#M57561</guid>
      <dc:creator>johntopley</dc:creator>
      <dc:date>2014-09-02T11:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198907#M57562</link>
      <description>&lt;P&gt;Here is what you want:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;rex "geog:([^\&amp;amp;]+)&amp;amp;([^\/]+)\\/\1:(?P&amp;lt;area&amp;gt;[^\&amp;amp;]+)"&lt;/CODE&gt;&lt;BR /&gt;
(be sure to escape the forward slash...the markdown is not allowing that to show.)&lt;/P&gt;

&lt;P&gt;The first capturing group grabs the value of geog and then later, you reference the first capturing group with the \1&lt;/P&gt;

&lt;P&gt;this worked for me.&lt;/P&gt;

&lt;P&gt;You can see exactly how it works if you put your event and the regex into something like regex101.com&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2014 14:58:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198907#M57562</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2014-09-02T14:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198908#M57563</link>
      <description>&lt;P&gt;That did the trick - thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Sep 2014 09:56:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198908#M57563</guid>
      <dc:creator>johntopley</dc:creator>
      <dc:date>2014-09-03T09:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a field's values and pass them to a new field using rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198909#M57564</link>
      <description>&lt;P&gt;Awesome! Thank you for accepting the answer. Be sure to vote it up as well so that it is more likely to bubble to the top when other folks are looking for something similar.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Sep 2014 15:10:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-field-s-values-and-pass-them-to/m-p/198909#M57564</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2014-09-03T15:10:10Z</dc:date>
    </item>
  </channel>
</rss>

