Remove over gsub regex

Hi
How to fix below code for remove all item with word " term" from many of fields,
one variant of fields

in example line "psm_info" => "7-5-term-term-term-term-term-"

I have tried some like this one, but it doesn't work as expected
there is something strange with "gsub" I don't have idea what's wrong

tmp = v.gsub!('-term', '')
tmp = v.gsub!('term', '')
event.set(k, tmp)

and at least decided to left regex in gsub:

ruby {
    code => "
      hash = event.to_hash
      hash.each do |k,v|
      if v.is_a? String 
       if  v.include? 'term-'
        event.set(k, v.gsub!('term-',''))
        end
       end
      end
    "
  }
ruby {
    code => "
      hash = event.to_hash
      hash.each do |k,v|
      if v.is_a? String 
       if  v.include? '-term'
        event.set(k, v.gsub!('-term',''))
        end
       end
      end
    "
  }

what will happen if you use gsub rather than gsub! in all places?

Yes, You're right thanks @Tomo_M I've read this article

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.