<?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: Regular Expression if then else in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333362#M99137</link>
    <description>&lt;P&gt;Can you please try below regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;Profilename&amp;gt;\w+)[\-]?(?&amp;lt;Profilestep&amp;gt;.*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to test this regex then please check &lt;A href="https://regex101.com/r/3XdfSv/2"&gt;https://regex101.com/r/3XdfSv/2&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Apr 2018 11:59:37 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2018-04-12T11:59:37Z</dc:date>
    <item>
      <title>Regular Expression if then else</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333360#M99135</link>
      <description>&lt;P&gt;Hello everyone.&lt;/P&gt;

&lt;P&gt;I have field which sometimes contains Profilename and Stepname and sometimes just the Profilename.&lt;BR /&gt;
I would like to extract the profilename and stepname.&lt;/P&gt;

&lt;P&gt;Example: Test_Profile-TestStep&lt;BR /&gt;
Test_Profile is the profilename&lt;BR /&gt;
TestStep is the stepname&lt;BR /&gt;
It`s always combined with an -&lt;/P&gt;

&lt;P&gt;So if there is no - then the whole field is the profilename.&lt;/P&gt;

&lt;P&gt;I´m absolutely not confirm with regular expressions. &lt;/P&gt;

&lt;P&gt;I`ve tried this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?(?=\b-\b)(?P&amp;lt;ProfileStep&amp;gt;[^-"]+)|(?P&amp;lt;ProfileStep&amp;gt;[^"]+))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But splunk says "Regex: two named subpatterns have the same name"&lt;/P&gt;

&lt;P&gt;I would be so happy about some help. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Kind regards&lt;BR /&gt;
Jessi&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:01:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333360#M99135</guid>
      <dc:creator>jessicadrechsel</dc:creator>
      <dc:date>2020-09-29T19:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression if then else</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333361#M99136</link>
      <description>&lt;P&gt;Got the problem solved for the profile name&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?J)(?(?=\b-\b)(?P&amp;lt;ProfileStep&amp;gt;[^"]+)|(?P&amp;lt;ProfileStep&amp;gt;[^-"]+))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I try to figure it out for the stepname&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?J)(?(?=\b-\b)(?+[^-"]P&amp;lt;Stepname&amp;gt;)|(?+[^"]P&amp;lt;Stepname&amp;gt;))      &amp;lt;== not working
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Apr 2018 11:12:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333361#M99136</guid>
      <dc:creator>jessicadrechsel</dc:creator>
      <dc:date>2018-04-12T11:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression if then else</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333362#M99137</link>
      <description>&lt;P&gt;Can you please try below regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;Profilename&amp;gt;\w+)[\-]?(?&amp;lt;Profilestep&amp;gt;.*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to test this regex then please check &lt;A href="https://regex101.com/r/3XdfSv/2"&gt;https://regex101.com/r/3XdfSv/2&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 11:59:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333362#M99137</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-04-12T11:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression if then else</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333363#M99138</link>
      <description>&lt;P&gt;Thats not working. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;For example a whole line - with stepname - looks like that:&lt;BR /&gt;
2018-04-13 08:13:51,"germany","e2e_appmon","GEV_Muenchen_DE_MU_X2SLM39","DE_MU_X2SLM39","GEV_ADPortal-Zusatzdaten_erfassen",2018-04-13 08:13:50,763,"QOS_E2E_EXECUTION"&lt;BR /&gt;
Profilename=GEV_ADPortal&lt;BR /&gt;
Stepname=Zusatzdaten_erfassen&lt;/P&gt;

&lt;P&gt;A line without stepname looks like that:&lt;BR /&gt;
2018-04-13 08:13:51,"germany","e2e_appmon","GEV_Muenchen_DE_MU_X2SLM39","DE_MU_X2SLM39","GEV_ADPortal",2018-04-13 08:13:50,763,"QOS_E2E_EXECUTION"&lt;BR /&gt;
Profilename=GEV_ADPortal&lt;BR /&gt;
Stepname= or if this is not possible then I can write the profilename in stepname&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:01:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333363#M99138</guid>
      <dc:creator>jessicadrechsel</dc:creator>
      <dc:date>2020-09-29T19:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression if then else</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333364#M99139</link>
      <description>&lt;P&gt;@jessicadrechsel,&lt;BR /&gt;
looking at your data, it seems like you have key value pairs there for Profilename and Stepname. best will be to extract permanently with field extractor, also i would suggest to check your data in verbose mode as splunk is pretty good at understanding &lt;CODE&gt;field=value&lt;/CODE&gt; structure.&lt;BR /&gt;
in any case try the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... your search ... | rex "Profilename=(?&amp;lt;Profilename&amp;gt;\S+)" 
                               | rex "Stepname=(?&amp;lt;Stepname&amp;gt;\S+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope  it helps&lt;/P&gt;</description>
      <pubDate>Sat, 14 Apr 2018 02:17:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-if-then-else/m-p/333364#M99139</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2018-04-14T02:17:52Z</dc:date>
    </item>
  </channel>
</rss>

