<?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: Regex Conditional Group Capture with Name in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-Conditional-Group-Capture-with-Name/m-p/48204#M11511</link>
    <description>&lt;P&gt;Use &lt;CODE&gt;coalesce&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... (?'SW_Date'd{14})|(?'SW_ClaimTrackNum'd+)|(?&amp;gt;(?'temp_NewBinNumber'[0-9]{6})||)(?&amp;gt;([A-z: ]+(?'SW_RespTime'[0-9.]+))|([A-z: ]+))|(?&amp;gt;(?'temp_OldBinNumber'[0-9]{6})(?'temp_RecvdClaimType'[0-9A-z]{4})|(?'temp_SentClaimType'[0-9A-z]{4})) | eval SW_BinNumber=coalesce(temp_NewBinNumber, temp_OldBinNumber) |eval SW_ClaimType=coalesce(temp_RecvdClaimType, temp_SentClaimType) | fields - temp*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 30 May 2015 14:52:56 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-05-30T14:52:56Z</dc:date>
    <item>
      <title>Regex Conditional Group Capture with Name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Conditional-Group-Capture-with-Name/m-p/48203#M11510</link>
      <description>&lt;P&gt;I'm trying to build 1 regex to capture multiple sets of data.  Below is a sample:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1. 20110221124637|21410|SENT:0.646861|51B11A011801830658
2. 20110221124854|21411|RECVD|00345251B1
3. 20110221124854|362|003452|SENT: 3.198847|51B11A011801830658
4. 20110221124854|362|003452|RECVD|00345251B1 
5. 20110221160534|431|011867|RECVD|01186751B1 
6. 20110221160534|431|011867|SENT: 0.278782|51B11A011801830658
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically these lines are from different versions of a piece of software, but all contain the same information in different places. These are the fields I'd like to extract: Date, BinNumber, ClaimTrackNum, Direction, RespTime and ClaimType.&lt;/P&gt;

&lt;P&gt;Here is the date:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1. 20110221124637         |21410|SENT:0.646861|51B11A011801830658
2. 20110221124854         |21411|RECVD|00345251B1
3. 20110221124854         |362|003452|SENT: 3.198847|51B11A011801830658
4. 20110221124854         |362|003452|RECVD|00345251B1 
5. 20110221160534         |431|011867|RECVD|01186751B1 
6. 20110221160534         |431|011867|SENT: 0.278782|51B11A011801830658    
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;ClaimTrackNum:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1. 20110221124637        |21410|        SENT:0.646861|51B11A011801830658
2. 20110221124854        |21411|        RECVD|00345251B1
3. 20110221124854        |362|          003452|SENT: 3.198847|51B11A011801830658
4. 20110221124854        |362|          003452|RECVD|00345251B1 
5. 20110221160534        |431|          011867|RECVD|01186751B1 
6. 20110221160534        |431|          011867|SENT: 0.278782|51B11A011801830658
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;BinNumber (May exist or not, or be in 2 spots):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1. 20110221124637|21410|SENT:0.646861|51B11A011801830658
2. 20110221124854|21411|RECVD|                            003452         51B1
3. 20110221124854|362|       003452        |SENT: 3.198847|51B11A011801830658
4. 20110221124854|362|       003452        |RECVD|        003452         51B1 
5. 20110221160534|431|       011867        |RECVD|        011867         51B1 
6. 20110221160534|431|       011867        |SENT: 0.278782|51B11A011801830658
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;RespTime (Only exists after a "SENT:" (old style) or "SENT: " (new)): &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1. 20110221124637|21410|SENT:        0.646861         |51B11A011801830658
2. 20110221124854|21411|RECVD|00345251B1
3. 20110221124854|362|003452|SENT:   3.198847         |51B11A011801830658
4. 20110221124854|362|003452|RECVD|00345251B1 
5. 20110221160534|431|011867|RECVD|01186751B1 
6. 20110221160534|431|011867|SENT:   0.278782         |51B11A011801830658
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;ClaimType:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1. 20110221124637|21410|SENT:0.646861|          51B1       1A011801830658
2. 20110221124854|21411|RECVD|003452            51B1
3. 20110221124854|362|003452|SENT: 3.198847|    51B1       1A011801830658
4. 20110221124854|362|003452|RECVD|003452       51B1 
5. 20110221160534|431|011867|RECVD|011867       51B1 
6. 20110221160534|431|011867|SENT: 0.278782|    51B1       1A011801830658
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And lastly the direction is either the word "SENT" or "RECVD"&lt;/P&gt;

&lt;P&gt;I've come up with this regex, which fully matches everything:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?'SW_Date'\d{14})\|(?'SW_ClaimTrackNum'\d+)\|(?&amp;gt;(?'SW_BinNumber'[0-9]{6})\||)(?&amp;gt;([A-z: ]+(?'SW_RespTime'[0-9.]+))|([A-z: ]+))\|(?&amp;gt;(?'SW_BinNumber'[0-9]{6})(?'SW_ClaimType'[0-9A-z]{4})|(?'SW_ClaimType'[0-9A-z]{4}))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which splunk doesn't like...  If I simply rename any duplicate field to different names, splunk doesn't have an issue.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?'SW_Date'\d{14})\|(?'SW_ClaimTrackNum'\d+)\|(?&amp;gt;(?'SW_NewBinNumber'[0-9]{6})\||)(?&amp;gt;([A-z: ]+(?'SW_RespTime'[0-9.]+))|([A-z: ]+))\|(?&amp;gt;(?'SW_OldBinNumber'[0-9]{6})(?'SW_RecvdClaimType'[0-9A-z]{4})|(?'SW_SentClaimType'[0-9A-z]{4}))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but naturally splunk now thinks that "newbinnumber" and "oldbinnumber" are different fields when they are the exact same.&lt;/P&gt;

&lt;P&gt;How can I write this regex to always extract those fields as "BinNumber" and "ClaimType"?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Feb 2011 08:03:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Conditional-Group-Capture-with-Name/m-p/48203#M11510</guid>
      <dc:creator>healthtrans</dc:creator>
      <dc:date>2011-02-22T08:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Conditional Group Capture with Name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Conditional-Group-Capture-with-Name/m-p/48204#M11511</link>
      <description>&lt;P&gt;Use &lt;CODE&gt;coalesce&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... (?'SW_Date'd{14})|(?'SW_ClaimTrackNum'd+)|(?&amp;gt;(?'temp_NewBinNumber'[0-9]{6})||)(?&amp;gt;([A-z: ]+(?'SW_RespTime'[0-9.]+))|([A-z: ]+))|(?&amp;gt;(?'temp_OldBinNumber'[0-9]{6})(?'temp_RecvdClaimType'[0-9A-z]{4})|(?'temp_SentClaimType'[0-9A-z]{4})) | eval SW_BinNumber=coalesce(temp_NewBinNumber, temp_OldBinNumber) |eval SW_ClaimType=coalesce(temp_RecvdClaimType, temp_SentClaimType) | fields - temp*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 May 2015 14:52:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Conditional-Group-Capture-with-Name/m-p/48204#M11511</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-30T14:52:56Z</dc:date>
    </item>
  </channel>
</rss>

