<?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 to find which group was matched in a regex when multiple groups are extracted to the same field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-which-group-was-matched-in-a-regex-when-multiple/m-p/301531#M90785</link>
    <description>&lt;P&gt;How and where are you doing this?  Is it search-time with SPL or is it index-time with configuration files?  Show us your "code".&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2017 21:20:18 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2017-07-07T21:20:18Z</dc:date>
    <item>
      <title>How to find which group was matched in a regex when multiple groups are extracted to the same field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-which-group-was-matched-in-a-regex-when-multiple/m-p/301530#M90784</link>
      <description>&lt;P&gt;I am using multiple capturing groups in regex and extracting the value of multiple groups to same field.&lt;/P&gt;

&lt;P&gt;For ex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(group1)|(group2)|(group3)|(group4)|(group5)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have defined a field extraction to extract values of &lt;CODE&gt;group1&lt;/CODE&gt;, &lt;CODE&gt;group2&lt;/CODE&gt; and &lt;CODE&gt;group3&lt;/CODE&gt; to one field ( say &lt;CODE&gt;field1&lt;/CODE&gt; ). Now If some data matched above regex (say &lt;CODE&gt;group2&lt;/CODE&gt; is matched), its value is extracted to &lt;CODE&gt;field1&lt;/CODE&gt;. At this point I know that one of the first 3 groups matched. But is there a way to find out which group matched out of the first 3 groups? I had to extract multiple group values to a single field because all those groups can contain similar data and all the groups does not get logged in one log statement. Also there are so many capturing groups and I don't want to have separate field extraction for each group.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 19:51:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-which-group-was-matched-in-a-regex-when-multiple/m-p/301530#M90784</guid>
      <dc:creator>girrajubharath</dc:creator>
      <dc:date>2017-07-07T19:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to find which group was matched in a regex when multiple groups are extracted to the same field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-which-group-was-matched-in-a-regex-when-multiple/m-p/301531#M90785</link>
      <description>&lt;P&gt;How and where are you doing this?  Is it search-time with SPL or is it index-time with configuration files?  Show us your "code".&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 21:20:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-which-group-was-matched-in-a-regex-when-multiple/m-p/301531#M90785</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-07-07T21:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to find which group was matched in a regex when multiple groups are extracted to the same field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-which-group-was-matched-in-a-regex-when-multiple/m-p/301532#M90786</link>
      <description>&lt;P&gt;I'm dubious about your statement that you &lt;EM&gt;had to&lt;/EM&gt;.  It sounds like you &lt;EM&gt;chose to&lt;/EM&gt;, and then you found that your choice has caused a problem you didn't anticipate. &lt;/P&gt;

&lt;P&gt;In essence, you are probably going to have to query the field to figure out what's in it, which would be more intuitive if you just extracted it into separate fields with the similar data named similarly and the different data named differently for each potential format.   &lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 20:50:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-which-group-was-matched-in-a-regex-when-multiple/m-p/301532#M90786</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-08T20:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to find which group was matched in a regex when multiple groups are extracted to the same field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-which-group-was-matched-in-a-regex-when-multiple/m-p/301533#M90787</link>
      <description>&lt;P&gt;You really can't.  Splunk does not expose how things were matched.  Now, for debugging purposes, if you want to be freakishly clever, you can do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;common_name&amp;gt;(?&amp;lt;unique1&amp;gt;a+))|(?&amp;lt;common_name&amp;gt;(?&amp;lt;unique2&amp;gt;b+))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Assuming Splunk has the regex library configured to allow for duplicate subpattern  names in a single regex (and I assume they do, but don't know this for a fact), then you could extract the field named &lt;CODE&gt;common_name&lt;/CODE&gt; either as "a+" or "b+" -- but in the "a+" case we would also extract "unique1", and in the "b+" case we would also extract "unique2".  This is taking advantage of some oddities of the regex engine.&lt;/P&gt;

&lt;P&gt;Fun fact:  This is also a semi-reasonable approach to replacing some instances of &lt;CODE&gt;FIELDALIAS&lt;/CODE&gt; and some edge cases for &lt;CODE&gt;EVAL&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 18:54:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-which-group-was-matched-in-a-regex-when-multiple/m-p/301533#M90787</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2017-07-09T18:54:27Z</dc:date>
    </item>
  </channel>
</rss>

