<?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: Can regex remove spaces inside a capture group? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416625#M119915</link>
    <description>&lt;P&gt;Thanks. In the future I will provide more details to start and I will reach out to the folks that administer Splunk for us to see what is the method they will implement.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Apr 2019 18:20:04 GMT</pubDate>
    <dc:creator>donemery</dc:creator>
    <dc:date>2019-04-15T18:20:04Z</dc:date>
    <item>
      <title>Can regex remove spaces inside a capture group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416618#M119908</link>
      <description>&lt;P&gt;I am using regex slot and port information.  Here is an example of the syslog output:&lt;/P&gt;

&lt;P&gt;Slot1 : OLTPort2&lt;/P&gt;

&lt;P&gt;Is it possible in regex to remove the spaces around the :?&lt;/P&gt;

&lt;P&gt;I would like it to look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Slot1:OLTPort2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;By using two captures I can use eval to combine two extracts but I would prefer to do it with regex, if possible.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where isnotnull(S_Slot) AND isnotnull(S_Port) | eval SlotAndPort = S_Slot . ":" . S_Port
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 17:03:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416618#M119908</guid>
      <dc:creator>donemery</dc:creator>
      <dc:date>2019-04-15T17:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Can regex remove spaces inside a capture group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416619#M119909</link>
      <description>&lt;P&gt;You need &lt;CODE&gt;rex&lt;/CODE&gt; command in sed mode. Assuming your field with both slot and port is SlotAndPort:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... your search ...
| rex field=SlotAndPort mode=sed "s/ //g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/Rex"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/Rex&lt;/A&gt; has more details.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 17:09:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416619#M119909</guid>
      <dc:creator>grittonc</dc:creator>
      <dc:date>2019-04-15T17:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Can regex remove spaces inside a capture group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416620#M119910</link>
      <description>&lt;P&gt;@donemery you can use &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29"&gt;replace()&lt;/A&gt; evaluation function to remove spaces from your data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="Slot1 : OLTPort2"
| eval dataWithoutSpace=replace(data,"\s","")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 17:16:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416620#M119910</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-04-15T17:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can regex remove spaces inside a capture group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416621#M119911</link>
      <description>&lt;P&gt;Assuming that your existing RegEx looks something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;Slot1&amp;gt;[^xyz]+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Change it to this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\s*(&amp;lt;Slot1&amp;gt;[^xyz\s]+)\s*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 17:17:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416621#M119911</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-04-15T17:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can regex remove spaces inside a capture group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416622#M119912</link>
      <description>&lt;P&gt;haha, I was overthinking. @niketnilay's answer is much better! This would be more useful if you needed to replace a pattern, not a particular character.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 17:24:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416622#M119912</guid>
      <dc:creator>grittonc</dc:creator>
      <dc:date>2019-04-15T17:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can regex remove spaces inside a capture group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416623#M119913</link>
      <description>&lt;P&gt;I can't get the \s* to work with my field extraction.  Maybe I am doing something wrong.&lt;/P&gt;

&lt;P&gt;Here is the full field extraction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^[^\[\n]*\[\s+(?P[S,s]lot\d+\s+\:\s+[O,U][L,p][T,l]\D{3,8}\d+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is an example of the data I am extracting from:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Apr 15 17:25:49 +00:00 HOST06-XXXX [ Slot4 : OLTPort3 : ONU7 : In service.]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 17:34:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416623#M119913</guid>
      <dc:creator>donemery</dc:creator>
      <dc:date>2019-04-15T17:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can regex remove spaces inside a capture group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416624#M119914</link>
      <description>&lt;P&gt;Always share as much as you can.  Now that we have your RegEx, your problem is clear.  You cannot fix it in a single step; it till take 2 and the 2 change depending on whether this is &lt;CODE&gt;search-time&lt;/CODE&gt; or &lt;CODE&gt;index-time&lt;/CODE&gt;, which again, you neglected to tell us.  In either case, add a new transform to the end of the existing &lt;CODE&gt;REPORT-&lt;/CODE&gt; or &lt;CODE&gt;TRANSFORMS-&lt;/CODE&gt; line called &lt;CODE&gt;StripSpaces&lt;/CODE&gt;.  Then put this in your &lt;CODE&gt;transforms.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[StripSpaces]
SOURCE_KEY = &amp;lt;YourExistingFieldNameWhichYouDidNotShare&amp;gt;
REGEX = (\S+)\s*:\s*(\S+)
FORMAT = $1::":"::$2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 18:05:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416624#M119914</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-04-15T18:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Can regex remove spaces inside a capture group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416625#M119915</link>
      <description>&lt;P&gt;Thanks. In the future I will provide more details to start and I will reach out to the folks that administer Splunk for us to see what is the method they will implement.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 18:20:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-regex-remove-spaces-inside-a-capture-group/m-p/416625#M119915</guid>
      <dc:creator>donemery</dc:creator>
      <dc:date>2019-04-15T18:20:04Z</dc:date>
    </item>
  </channel>
</rss>

