<?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 extract string before specific character in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-string-before-specific-character/m-p/650111#M224757</link>
    <description>&lt;P&gt;Hello. I want to extract strings anything comes before "|" .&lt;/P&gt;&lt;P&gt;ex.&lt;BR /&gt;Math |&lt;BR /&gt;Math | Science | Math&lt;BR /&gt;English | Math&lt;BR /&gt;Science | Science | Science | Science&lt;/P&gt;&lt;P&gt;Expected result:&lt;BR /&gt;Math&lt;BR /&gt;Math&lt;BR /&gt;English&lt;BR /&gt;Science&lt;/P&gt;&lt;P&gt;Below search did not worked.&lt;/P&gt;&lt;P&gt;my search | stats count by Subject="(?&amp;lt;Subject&amp;gt;[^\|]+)"&lt;/P&gt;&lt;P&gt;Please help me out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2023 08:07:06 GMT</pubDate>
    <dc:creator>marinella26</dc:creator>
    <dc:date>2023-07-12T08:07:06Z</dc:date>
    <item>
      <title>How to extract string before specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-string-before-specific-character/m-p/650111#M224757</link>
      <description>&lt;P&gt;Hello. I want to extract strings anything comes before "|" .&lt;/P&gt;&lt;P&gt;ex.&lt;BR /&gt;Math |&lt;BR /&gt;Math | Science | Math&lt;BR /&gt;English | Math&lt;BR /&gt;Science | Science | Science | Science&lt;/P&gt;&lt;P&gt;Expected result:&lt;BR /&gt;Math&lt;BR /&gt;Math&lt;BR /&gt;English&lt;BR /&gt;Science&lt;/P&gt;&lt;P&gt;Below search did not worked.&lt;/P&gt;&lt;P&gt;my search | stats count by Subject="(?&amp;lt;Subject&amp;gt;[^\|]+)"&lt;/P&gt;&lt;P&gt;Please help me out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 08:07:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-string-before-specific-character/m-p/650111#M224757</guid>
      <dc:creator>marinella26</dc:creator>
      <dc:date>2023-07-12T08:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string before specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-string-before-specific-character/m-p/650114#M224759</link>
      <description>&lt;P&gt;Read&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex" target="_blank" rel="noopener"&gt;rex&lt;/A&gt;. &amp;nbsp;stats command doesn't have a function to do extraction.&lt;/P&gt;&lt;P&gt;Meanwhile, your sample code suggests that Splunk gives you a field named &lt;FONT face="courier new,courier"&gt;Subject&lt;/FONT&gt; and you are trying to get some info from this field. &amp;nbsp;If this is the case, there is a slightly more efficient way using &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions#split.28.26lt.3Bstr.26gt.3B.2C.26lt.3Bdelim.26gt.3B.29" target="_blank" rel="noopener"&gt;split&lt;/A&gt; function:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;my search
| Subject = mvindex(split(Subject, "|"), 0)
| stats count by Subject&lt;/LI-CODE&gt;&lt;P&gt;Another way equivalent to rex is to use&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#replace.28.26lt.3Bstr.26gt.3B.2C.26lt.3Bregex.26gt.3B.2C.26lt.3Breplacement.26gt.3B.29" target="_blank" rel="noopener"&gt;replace&lt;/A&gt;&amp;nbsp;function.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 08:26:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-string-before-specific-character/m-p/650114#M224759</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-07-12T08:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string before specific character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-string-before-specific-character/m-p/650115#M224760</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/258089"&gt;@marinella26&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;you can use:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "^(?&amp;lt;field&amp;gt;[^\|]+)"&lt;/LI-CODE&gt;&lt;P&gt;that you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/6Ynayk/1" target="_blank"&gt;https://regex101.com/r/6Ynayk/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 08:33:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-string-before-specific-character/m-p/650115#M224760</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-07-12T08:33:43Z</dc:date>
    </item>
  </channel>
</rss>

