<?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 do I optimize my regex for a field extraction to improve efficiency and searchability? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146282#M40842</link>
    <description>&lt;P&gt;your one works on regex101 on one event but if I add more events it does not seem to work?&lt;BR /&gt;
but my one seems to work in splunk for all events.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Jul 2015 02:11:24 GMT</pubDate>
    <dc:creator>HattrickNZ</dc:creator>
    <dc:date>2015-07-29T02:11:24Z</dc:date>
    <item>
      <title>How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146280#M40840</link>
      <description>&lt;P&gt;I am working on field extraction in splunk and I have come up with the below regex&lt;/P&gt;

&lt;P&gt;(spunk regex does not work the same &lt;A href="http://regexr.com/3bfuq"&gt;here&lt;/A&gt;)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^[^'\n]*'(?P&amp;lt;field1&amp;gt;\d+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which pulls this value out: &lt;BR /&gt;
&lt;CODE&gt;79037030601&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;of the following events: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;beginTime="2015-07-29T09:00:00+12:00",elementType="MSCServer",userLabel="MSCKPR",measInfoId=83888334,duration="PT3600S",endTime="2015-07-29T10:00:00+12:00",measObjLdn="MSCKPR/ALL HLR:MSCKPR/HLR Number:HLR Number = K'79037030601",c84162779=1,c84162780=1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now what I am looking at doing is optimizing this regex for time efficiency and searchability in the events. &lt;BR /&gt;
I am trying to use &lt;A href="http://www.regexr.com/"&gt;here&lt;/A&gt;  to help me optimize it. One example i am working on here is &lt;A href="http://regexr.com/3bfun"&gt;this&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;How can i work on this regex and then be able to apply it to splunk? I don't think they are the same or are they? &lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2015 01:25:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146280#M40840</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2015-07-29T01:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146281#M40841</link>
      <description>&lt;P&gt;Hi HattrickNZ,&lt;/P&gt;

&lt;P&gt;using &lt;A href="https://regex101.com/"&gt;https://regex101.com/&lt;/A&gt; and your provided example I came up with this easy regex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;'(?P&amp;lt;field1&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does this work for all events?&lt;/P&gt;

&lt;P&gt;UPDATE: to use it in Splunk use this &lt;CODE&gt;.. | rex "'(?P\d+)\"" | ...&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2015 01:52:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146281#M40841</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-07-29T01:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146282#M40842</link>
      <description>&lt;P&gt;your one works on regex101 on one event but if I add more events it does not seem to work?&lt;BR /&gt;
but my one seems to work in splunk for all events.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2015 02:11:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146282#M40842</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2015-07-29T02:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146283#M40843</link>
      <description>&lt;P&gt;can you provide the others as well?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2015 02:12:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146283#M40843</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-07-29T02:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146284#M40844</link>
      <description>&lt;P&gt;and did you use the /g flag to match global in regex101&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2015 02:12:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146284#M40844</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-07-29T02:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146285#M40845</link>
      <description>&lt;P&gt;tks&lt;BR /&gt;
the global /g flag got it and it works on all events &lt;/P&gt;

&lt;P&gt;but what is the difference in this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^[^'\n]*'(?P&amp;lt;field1&amp;gt;\d+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;'(?P&amp;lt;feild1&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;looks like the only difference is ^[^'\n]* these characters are missing from the start. &lt;/P&gt;

&lt;P&gt;Also this does not work in splunk(get Unbalanced quotes. Error): &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;...  | rex '(?P\d+)" | stats count(feild1) by feild&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;But this does: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | rex  "^[^'\n]*'(?P\d+)" | stats count(feild2) by feild2&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Sorry for all the Qs just trying to understand this better.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2015 02:42:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146285#M40845</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2015-07-29T02:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146286#M40846</link>
      <description>&lt;P&gt;it should be like this in Splunk:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "'(?P&amp;lt;field&amp;gt;\d+)\"" | stats count(field1) by field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and to explain it; it will match a &lt;CODE&gt;'&lt;/CODE&gt; single quote and creates a matching group of all digits until the next &lt;CODE&gt;"&lt;/CODE&gt; double quote. Where as your original regex was like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^ assert position at start of the string
[^'\n]* match a single character not present in the list below
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
' the literal character '
\n matches a line-feed (newline) character (ASCII 10)
' matches the character ' literally
(?P&amp;lt;field1&amp;gt;\d+) Named capturing group field1
\d+ match a digit [0-9]
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jul 2015 02:51:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146286#M40846</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-07-29T02:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146287#M40847</link>
      <description>&lt;P&gt;For my reference: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;'(?P&amp;lt;field1&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;'   - finds the first '&lt;BR /&gt;
\d+     - \d finds the first digit after '(single quote) + finds all digits that follow and stops before the "(double quote)&lt;BR /&gt;
()  - this has something to do with what to capture &lt;BR /&gt;
?P  - not sure but think it picks the first character for selection OR matches the character P literally (case sensitive) OR might have something to do with storing it in the field name name1&lt;/P&gt;

&lt;P&gt;for example &lt;BR /&gt;
'\d+        - will highlight '79037030601&lt;BR /&gt;
'(?P)\d+    - will hightlight '79037030601 but it looks like it the cursor is just before the first 7 -- not sure if the ?P is required&lt;BR /&gt;
'(\d+)      - will hightlight '79037030601 and highlights the numbers 79037030601 in blue and ' in green -- soo not sure if the ?P is required &lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2015 03:44:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146287#M40847</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2015-07-29T03:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146288#M40848</link>
      <description>&lt;P&gt;the &lt;CODE&gt;(? )&lt;/CODE&gt; is for &lt;CODE&gt;a named matching group&lt;/CODE&gt; and you can use the &lt;CODE&gt;P&lt;/CODE&gt; with in or not, both will work. As well in regex101.com you will get the explanation of your regex on the top right side&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2015 03:48:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146288#M40848</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-07-29T03:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I optimize my regex for a field extraction to improve efficiency and searchability?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146289#M40849</link>
      <description>&lt;P&gt;To see the efficiency of your regexes more detailed than the indication of steps displayed above the regex, you can also use the debug mode of regex101.com to the left to see where you might run into unnecessary steps (and to learn how regexes work in general).&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2015 08:51:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-optimize-my-regex-for-a-field-extraction-to-improve/m-p/146289#M40849</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-07-29T08:51:14Z</dc:date>
    </item>
  </channel>
</rss>

