<?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 use regex inside eval? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-inside-eval/m-p/332750#M98991</link>
    <description>&lt;P&gt;If all the things you're looking to count match that same pattern, then you'd be well suited to extract the value from that pattern and count based on the extracted value.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=cs_uri_stem "\/HomeOwners\/sales\/v\d\/\d{8,}\/(?&amp;lt;endpoint&amp;gt;[^\/]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this more succinct regex would probably even work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=cs_uri_stem "(?&amp;lt;endpoint&amp;gt;[^\/]+)$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then to populate the &lt;CODE&gt;counter&lt;/CODE&gt; field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats count AS counter BY endpoint
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And if you just need the counter and not the rest of the event data, you could use &lt;CODE&gt;stats&lt;/CODE&gt; instead of &lt;CODE&gt;eventstats&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count AS counter BY endpoint
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Mar 2018 21:53:54 GMT</pubDate>
    <dc:creator>elliotproebstel</dc:creator>
    <dc:date>2018-03-06T21:53:54Z</dc:date>
    <item>
      <title>How to use regex inside eval?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-inside-eval/m-p/332749#M98990</link>
      <description>&lt;P&gt;I need to use regex inside the eval as I have to use multiple regexs inside of it. I am writing something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval counter=case( 
 | regex cs_uri_stem = "/**/sales/v\d/\d{8,}/***", "******", 
 | regex cs_uri_stem = "/**/sales/v\d/\d{8,}/**", "**"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to include more regexs to get the count of each single endpint&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 21:27:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-inside-eval/m-p/332749#M98990</guid>
      <dc:creator>kollachandra</dc:creator>
      <dc:date>2018-03-06T21:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to use regex inside eval?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-inside-eval/m-p/332750#M98991</link>
      <description>&lt;P&gt;If all the things you're looking to count match that same pattern, then you'd be well suited to extract the value from that pattern and count based on the extracted value.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=cs_uri_stem "\/HomeOwners\/sales\/v\d\/\d{8,}\/(?&amp;lt;endpoint&amp;gt;[^\/]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this more succinct regex would probably even work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=cs_uri_stem "(?&amp;lt;endpoint&amp;gt;[^\/]+)$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then to populate the &lt;CODE&gt;counter&lt;/CODE&gt; field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats count AS counter BY endpoint
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And if you just need the counter and not the rest of the event data, you could use &lt;CODE&gt;stats&lt;/CODE&gt; instead of &lt;CODE&gt;eventstats&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count AS counter BY endpoint
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 21:53:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-inside-eval/m-p/332750#M98991</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-03-06T21:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use regex inside eval?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-inside-eval/m-p/332751#M98992</link>
      <description>&lt;P&gt;I want to get the average of different API calls hosted on the same set of servers. I need to write regex as it has a differnt session in the call syntax(sales/v1/54571418/Purchases). So, what I need is get the avg of all the endpoints like&lt;BR /&gt;
                                                                 Endpoint             avg time&lt;BR /&gt;
sales/v1/*****&lt;STRONG&gt;&lt;EM&gt;/Purchases            Purchases            12&lt;BR /&gt;
sales/v1/&lt;/EM&gt;&lt;/STRONG&gt;**&lt;STRONG&gt;&lt;EM&gt;/Documents         Documents           10&lt;BR /&gt;
sales/v1/&lt;/EM&gt;&lt;/STRONG&gt;**&lt;STRONG&gt;&lt;EM&gt;/Addresses           Addresses             11&lt;BR /&gt;
sales/v1/&lt;/EM&gt;&lt;/STRONG&gt;*****/Purchases          Purchases              12&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 22:01:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-inside-eval/m-p/332751#M98992</guid>
      <dc:creator>kollachandra</dc:creator>
      <dc:date>2018-03-06T22:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to use regex inside eval?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-inside-eval/m-p/332752#M98993</link>
      <description>&lt;P&gt;So let's take it one step at a time. Is this &lt;CODE&gt;rex&lt;/CODE&gt; command working to extract your endpoints?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=cs_uri_stem "(?&amp;lt;endpoint&amp;gt;[^\/]+)$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If not, can you post some examples of the full contents of the &lt;CODE&gt;cs_uri_stem&lt;/CODE&gt; field where it's not working? It's best if you use the &lt;CODE&gt;101010&lt;/CODE&gt; code button to ensure none of the characters you're posting get eaten by the posting software. Or if those endpoints aren't in the &lt;CODE&gt;cs_uri_stem&lt;/CODE&gt; field and I misunderstood your original post, please share the full values of the fields where the endpoints are contained. We'll get it sorted!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 03:51:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-inside-eval/m-p/332752#M98993</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-03-07T03:51:10Z</dc:date>
    </item>
  </channel>
</rss>

