<?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 edit my &amp;quot;rex mode=sed...&amp;quot; statement to remove square brackets and the content within them from a field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282215#M85195</link>
    <description>&lt;P&gt;Your regex matches everything except the closing square bracket so that's why the closing square bracket remains.  Try this expression:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed field=name "s/\[[\w\]]*//"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 06 Jun 2016 18:04:51 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2016-06-06T18:04:51Z</dc:date>
    <item>
      <title>How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282214#M85194</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I need to remove square brackets and content within it from a field in a search.&lt;/P&gt;

&lt;P&gt;eg: &lt;BR /&gt;
Input: My name is John [Employee] &lt;BR /&gt;
Output: My name is John&lt;/P&gt;

&lt;P&gt;I tried with the following expression: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed field="name" "s/\[[^]]*//"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It returns output as: &lt;CODE&gt;My name is John ]&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I don't want the closing square bracket.&lt;/P&gt;

&lt;P&gt;How do I modify the above pattern so that I get the desired output?&lt;/P&gt;

&lt;P&gt;Thanks &lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 17:54:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282214#M85194</guid>
      <dc:creator>amoldesai</dc:creator>
      <dc:date>2016-06-06T17:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282215#M85195</link>
      <description>&lt;P&gt;Your regex matches everything except the closing square bracket so that's why the closing square bracket remains.  Try this expression:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed field=name "s/\[[\w\]]*//"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2016 18:04:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282215#M85195</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-06-06T18:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282216#M85196</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex mode=sed field=name "s/(\[.*\])//g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2016 18:08:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282216#M85196</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-06-06T18:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282217#M85197</link>
      <description>&lt;P&gt;Thanks for your quick reply.&lt;/P&gt;

&lt;P&gt;Sorry I did not mention that  content in the bracket contains space character.&lt;/P&gt;

&lt;P&gt;Using the sed expression that you provided , here is the input and output  :&lt;/P&gt;

&lt;P&gt;input :  My name is John [Employee Name] &lt;/P&gt;

&lt;P&gt;output : My name is John Name]&lt;/P&gt;

&lt;P&gt;I need the output as: My name is John&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 18:20:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282217#M85197</guid>
      <dc:creator>amoldesai</dc:creator>
      <dc:date>2016-06-06T18:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282218#M85198</link>
      <description>&lt;P&gt;Insert a space in the regex.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed field=name "s/\[[\w\s\]]*//"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2016 18:24:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282218#M85198</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-06-06T18:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282219#M85199</link>
      <description>&lt;P&gt;The safest option would be this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed field="name" "s/\[[^\]]+\]//"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2016 18:29:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282219#M85199</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-06-06T18:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282220#M85200</link>
      <description>&lt;P&gt;Thank you so much all of you for quickly looking into this problem. But still it does not work :&lt;/P&gt;

&lt;P&gt;@richgalloway: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed field=name "s/\[[\w\s\]]*//"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;output: No result found&lt;/P&gt;

&lt;P&gt;@somesoni2: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed field="name" "s/\[[^\]]+\]//"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;output: No result found&lt;/P&gt;

&lt;P&gt;Sundareshr: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed field=name "s/(\[.*\])//g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;output: No result found&lt;/P&gt;

&lt;P&gt;Here is the precise input string: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Cisco 1800 Series Integrated Services Routers [XYZ ARIZONA]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(with just Customer name replaced with XYZ)&lt;/P&gt;

&lt;P&gt;In fact, I tested all the  above regular  expression using online website: &lt;A href="https://regex101.com/"&gt;https://regex101.com/&lt;/A&gt; and found all above expressions are valid and return desired results.&lt;/P&gt;

&lt;P&gt;But in the context of Splunk search, it fails for me. Any idea?&lt;/P&gt;

&lt;P&gt;I am using Splunk 6.3 .&lt;/P&gt;

&lt;P&gt;Here is the complete search [productFamily is the field in consideration] :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[|inputlookup kvstore_lookup_prodfamily | eval KeyID = _key|where KeyID ="XYZ"|rename prodfamily.name as prodfamilyName |rename prodfamily.value as prodfamilyValue | eval reading=mvzip(prodfamilyName, prodfamilyValue)|fields reading | mvexpand reading | makemv reading delim="," |eval productFamily=mvindex(reading, 0) |rex mode=sed field="productFamily" "s/[[\w\s]]*//" ]  |table productFamily
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 19:19:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282220#M85200</guid>
      <dc:creator>amoldesai</dc:creator>
      <dc:date>2016-06-06T19:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282221#M85201</link>
      <description>&lt;P&gt;Let's gets the regex part first. Try this runanywhere sample search and let me know if the output is what you wanted.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval name=" Cisco 1800 Series Integrated Services Routers [XYZ ARIZONA]" | table name | eval orig_name=name| rex mode=sed field="name" "s/\[[^\]]+\]//"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try this as well (your query)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |inputlookup kvstore_lookup_prodfamily | eval KeyID = _key|where KeyID ="XYZ"|rename prodfamily.name as prodfamilyName |rename prodfamily.value as prodfamilyValue | eval reading=mvzip(prodfamilyName, prodfamilyValue)|fields reading | mvexpand reading | makemv reading delim="," |eval productFamily=mvindex(reading, 0) | rex mode=sed field="productFamily" "s/\[[^\]]+\]//"  |table productFamily
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2016 20:35:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282221#M85201</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-06-06T20:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282222#M85202</link>
      <description>&lt;P&gt;Please update this description with more detail information you described in a part of answers so that readers can understand your question clearer. &lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 23:10:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282222#M85202</guid>
      <dc:creator>Masa</dc:creator>
      <dc:date>2016-06-06T23:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit my "rex mode=sed..." statement to remove square brackets and the content within them from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282223#M85203</link>
      <description>&lt;P&gt;The first runanywhere  sample search works fine and even the second one.But when run in the context of my query which has subsearch, it does not work.I am not sure on the root cause though.Fortunately, with the below query , I am able to get desired result: &lt;BR /&gt;
|makemv productFamily delim=" ["|eval productFamily=mvindex(productFamily, 0)&lt;/P&gt;

&lt;P&gt;I have confirmed the regular expression provided by you and other boarders is correct using the runanywhere sample. Thanks again for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 16:08:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-edit-my-quot-rex-mode-sed-quot-statement-to-remove/m-p/282223#M85203</guid>
      <dc:creator>amoldesai</dc:creator>
      <dc:date>2016-06-07T16:08:51Z</dc:date>
    </item>
  </channel>
</rss>

