<?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 a regular expression to identify multiple capturing groups? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-identify-multiple-capturing/m-p/274812#M82894</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;
below is the stanza in transforms.conf.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  [rfc5424_header]
  REGEX = &amp;lt;(\d+)&amp;gt;\d{1}\s{1}\S+\s{1}\S+\s{1}(\S+)\s{1}(\S+)\s{1}(\S+)
  FORMAT = prival::$1 appname::$2 procid::$3 msgid::$4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As given, above regex has four capturing groups $1,$2,$3,$4. how to identify how many capturing groups are present in a regular expression?&lt;/P&gt;

&lt;P&gt;I know how to write regex to match a text and write regex with single name capturing group, but how do I write regex with multiple capturing groups to extract fields?  Don't understand what part of regex represents $1, $2 etc.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2017 21:23:36 GMT</pubDate>
    <dc:creator>ankithreddy777</dc:creator>
    <dc:date>2017-02-02T21:23:36Z</dc:date>
    <item>
      <title>How to write a regular expression to identify multiple capturing groups?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-identify-multiple-capturing/m-p/274812#M82894</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
below is the stanza in transforms.conf.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  [rfc5424_header]
  REGEX = &amp;lt;(\d+)&amp;gt;\d{1}\s{1}\S+\s{1}\S+\s{1}(\S+)\s{1}(\S+)\s{1}(\S+)
  FORMAT = prival::$1 appname::$2 procid::$3 msgid::$4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As given, above regex has four capturing groups $1,$2,$3,$4. how to identify how many capturing groups are present in a regular expression?&lt;/P&gt;

&lt;P&gt;I know how to write regex to match a text and write regex with single name capturing group, but how do I write regex with multiple capturing groups to extract fields?  Don't understand what part of regex represents $1, $2 etc.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 21:23:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-identify-multiple-capturing/m-p/274812#M82894</guid>
      <dc:creator>ankithreddy777</dc:creator>
      <dc:date>2017-02-02T21:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a regular expression to identify multiple capturing groups?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-identify-multiple-capturing/m-p/274813#M82895</link>
      <description>&lt;P&gt;Hi Ankit&lt;/P&gt;

&lt;P&gt;&amp;lt;&lt;STRONG&gt;(\d+)&lt;/STRONG&gt;&amp;gt;\d{1}\s{1}\S+\s{1}\S+\s{1}&lt;STRONG&gt;(\S+)&lt;/STRONG&gt;\s{1}&lt;STRONG&gt;(\S+)&lt;/STRONG&gt;\s{1}&lt;STRONG&gt;(\S+)&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;which are enclosed in () is the capturing group&lt;/P&gt;

&lt;P&gt;(\d+)  - 1st group&lt;BR /&gt;
(\S+) - 2nd&lt;BR /&gt;
(\S+)- 3 rd&lt;BR /&gt;
(\S+)-4 th&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 21:47:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-identify-multiple-capturing/m-p/274813#M82895</guid>
      <dc:creator>mpreddy</dc:creator>
      <dc:date>2017-02-02T21:47:43Z</dc:date>
    </item>
  </channel>
</rss>

