<?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: Regex ignore adding underscore if there is a dash in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419706#M120680</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;Try this

| makeresults
| eval attachment="Filename ABC - 2019 111 CT.pdf"
| rex mode=sed field=attachment "s/\s-\s/-/g"
| rex mode=sed field=attachment "s/\s/_/g" 
| table attachment
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 Apr 2019 17:51:24 GMT</pubDate>
    <dc:creator>saurabhkharkar</dc:creator>
    <dc:date>2019-04-18T17:51:24Z</dc:date>
    <item>
      <title>Regex ignore adding underscore if there is a dash</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419705#M120679</link>
      <description>&lt;P&gt;Hey everyone. So what I need to do is complete the filename in one of my fields in an event. Example is this:&lt;/P&gt;

&lt;P&gt;attachment = Filename ABC -  2019 111 CT.pdf&lt;/P&gt;

&lt;P&gt;I am using the command: &lt;STRONG&gt;| rex mode=sed field=attachment "s/ /_/g"&lt;/STRONG&gt;   to replace the whitespace with underscores. &lt;/P&gt;

&lt;P&gt;Question: How do I go about ignoring the whitespace before and after the dash. I am getting &lt;STRONG&gt;Filename_ABC_- _2019_111_CT.pdf&lt;/STRONG&gt; when it needs to be &lt;STRONG&gt;Filename_ABC-2019_111_CT.pdf&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Any help would be great. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:11:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419705#M120679</guid>
      <dc:creator>mcarthurnick</dc:creator>
      <dc:date>2020-09-30T00:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Regex ignore adding underscore if there is a dash</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419706#M120680</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;Try this

| makeresults
| eval attachment="Filename ABC - 2019 111 CT.pdf"
| rex mode=sed field=attachment "s/\s-\s/-/g"
| rex mode=sed field=attachment "s/\s/_/g" 
| table attachment
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Apr 2019 17:51:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419706#M120680</guid>
      <dc:creator>saurabhkharkar</dc:creator>
      <dc:date>2019-04-18T17:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Regex ignore adding underscore if there is a dash</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419707#M120681</link>
      <description>&lt;P&gt;Try this : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval attachment="Filename ABC - 2019 111 CT.pdf" 
| eval attachment=replace(attachment,"\s-\s","-"),attachment=replace(attachment,"\s","_")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:04:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419707#M120681</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-04-18T18:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Regex ignore adding underscore if there is a dash</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419708#M120682</link>
      <description>&lt;P&gt;This seemed to work for me. Thanks!&lt;/P&gt;

&lt;P&gt;Can you explain to me how that works in some detail? Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:14:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419708#M120682</guid>
      <dc:creator>mcarthurnick</dc:creator>
      <dc:date>2019-04-18T18:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Regex ignore adding underscore if there is a dash</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419709#M120683</link>
      <description>&lt;P&gt;Well, it's pretty simple, &lt;/P&gt;

&lt;P&gt;replace is a text function of eval command. It has 3 arguments say, X, Y, Z. This function returns a string formed by substituting string Z for every occurrence of regex string Y in field value X.&lt;/P&gt;

&lt;P&gt;Find a detailed explanation here:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:21:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419709#M120683</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-04-18T18:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Regex ignore adding underscore if there is a dash</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419710#M120684</link>
      <description>&lt;P&gt;Greatly Appreciated! Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2019 13:50:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-ignore-adding-underscore-if-there-is-a-dash/m-p/419710#M120684</guid>
      <dc:creator>mcarthurnick</dc:creator>
      <dc:date>2019-04-19T13:50:11Z</dc:date>
    </item>
  </channel>
</rss>

