<?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 How. to replace string if preceded or followed by particular characters? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610358#M212245</link>
    <description>&lt;P&gt;Given the below example events:&lt;/P&gt;
&lt;P&gt;Initial event:&lt;/P&gt;
&lt;PRE&gt;[stuff] apple.bean.carrot2donut.57.egg.fish(10) max:311 min 15 avg 101 low:1[stuff]&lt;/PRE&gt;
&lt;P&gt;Result event 1:&lt;/P&gt;
&lt;PRE&gt;[stuff] apple.bean.carrot&amp;amp;donut.&amp;amp;.egg.fish(&amp;amp;) max:&amp;amp; min &amp;amp; avg &amp;amp; low:&amp;amp;[stuff]&lt;/PRE&gt;
&lt;P&gt;Result event 2:&lt;/P&gt;
&lt;PRE&gt;[stuff] apple.bean.carrot2donut.57.egg.fish(&amp;amp;) max:&amp;amp; min &amp;amp; avg &amp;amp; low:&amp;amp;[stuff]&lt;/PRE&gt;
&lt;P&gt;I want to get Result 2 rather than Result 1.&amp;nbsp; I want to replace any series of numbers with an ampersand only if one of three conditions are true.&amp;nbsp; These conditions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The number series is preceded by a space.&lt;/LI&gt;
&lt;LI&gt;The number series is preceded by a colon.&lt;/LI&gt;
&lt;LI&gt;The number series is preceded by an open parenthesis and followed by a closed parenthesis.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;If I use the replace line below, the new variable created will contain Result 1 rather than the Result 2 I desire.&lt;/P&gt;
&lt;PRE&gt;| eval event = replace(_raw, "[0-9]+", "&amp;amp;")&lt;/PRE&gt;
&lt;P&gt;How do I get Result 2 instead?&lt;/P&gt;</description>
    <pubDate>Mon, 22 Aug 2022 15:14:37 GMT</pubDate>
    <dc:creator>firstname</dc:creator>
    <dc:date>2022-08-22T15:14:37Z</dc:date>
    <item>
      <title>How. to replace string if preceded or followed by particular characters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610358#M212245</link>
      <description>&lt;P&gt;Given the below example events:&lt;/P&gt;
&lt;P&gt;Initial event:&lt;/P&gt;
&lt;PRE&gt;[stuff] apple.bean.carrot2donut.57.egg.fish(10) max:311 min 15 avg 101 low:1[stuff]&lt;/PRE&gt;
&lt;P&gt;Result event 1:&lt;/P&gt;
&lt;PRE&gt;[stuff] apple.bean.carrot&amp;amp;donut.&amp;amp;.egg.fish(&amp;amp;) max:&amp;amp; min &amp;amp; avg &amp;amp; low:&amp;amp;[stuff]&lt;/PRE&gt;
&lt;P&gt;Result event 2:&lt;/P&gt;
&lt;PRE&gt;[stuff] apple.bean.carrot2donut.57.egg.fish(&amp;amp;) max:&amp;amp; min &amp;amp; avg &amp;amp; low:&amp;amp;[stuff]&lt;/PRE&gt;
&lt;P&gt;I want to get Result 2 rather than Result 1.&amp;nbsp; I want to replace any series of numbers with an ampersand only if one of three conditions are true.&amp;nbsp; These conditions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The number series is preceded by a space.&lt;/LI&gt;
&lt;LI&gt;The number series is preceded by a colon.&lt;/LI&gt;
&lt;LI&gt;The number series is preceded by an open parenthesis and followed by a closed parenthesis.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;If I use the replace line below, the new variable created will contain Result 1 rather than the Result 2 I desire.&lt;/P&gt;
&lt;PRE&gt;| eval event = replace(_raw, "[0-9]+", "&amp;amp;")&lt;/PRE&gt;
&lt;P&gt;How do I get Result 2 instead?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 15:14:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610358#M212245</guid>
      <dc:creator>firstname</dc:creator>
      <dc:date>2022-08-22T15:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string if preceded or followed by particular characters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610359#M212246</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/248248"&gt;@firstname&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;please try with a regex like the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults | eval my_field="[stuff] apple.bean.carrot2donut.57.egg.fish(10) max:311 min 15 [stuff]"
| append [ | makeresults | eval my_field="[stuff] apple.bean.carrot&amp;amp;donut.&amp;amp;.egg.fish(&amp;amp;) max:&amp;amp; min &amp;amp; [stuff]"]
| append [ | makeresults | eval my_field="[stuff] apple.bean.carrot2donut.57.egg.fish(&amp;amp;) max:&amp;amp; min &amp;amp; [stuff]"]
| rex field=my_field mode=sed "s/(\d+)/(\&amp;amp;)/g"&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 15:12:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610359#M212246</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-08-22T15:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: How. to replace string if preceded or followed by particular characters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610360#M212247</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex mode=sed "s/(?&amp;lt;a&amp;gt;\s|\:)(?&amp;lt;b&amp;gt;\d+)/\1\&amp;amp;/g s/\(\d+\)/(\&amp;amp;)/g"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 06:20:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610360#M212247</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-08-23T06:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: How. to replace string if preceded or followed by particular characters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610366#M212250</link>
      <description>&lt;P&gt;I think this is almost correct.&amp;nbsp; It doesn't seem to catch the parentheses condition.&amp;nbsp; I've tried to omit a closing parenthesis&lt;/P&gt;&lt;PRE&gt;| rex mode=sed "s/(?&amp;lt;a&amp;gt;\s|\:|\((?&amp;lt;b&amp;gt;\d+)/\1\&amp;amp;/g"&lt;/PRE&gt;&lt;P&gt;However, Splunk will not allow this search without the closing parenthesis.&amp;nbsp; I see how this is used to have "or" conditions, but is it possible to use such conditions to allow the stated parentheses condition?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 16:38:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610366#M212250</guid>
      <dc:creator>firstname</dc:creator>
      <dc:date>2022-08-22T16:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: How. to replace string if preceded or followed by particular characters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610445#M212293</link>
      <description>&lt;P&gt;Updated solution - essentially you would need to do two substitutions, but these can be done in the same rex&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 06:21:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-replace-string-if-preceded-or-followed-by-particular/m-p/610445#M212293</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-08-23T06:21:34Z</dc:date>
    </item>
  </channel>
</rss>

