Last Updated: February 25, 2016
·
470
· gwinn

How to remove redundant "Re:" in the email subject

def subject_clean(subject)
  result = subject.dup
  if result.scan(/(Re:\s)+?/i).length > 0 or !result.match(/Re\[\d+\]:\s/i).nil?
    result = "Re: #{result.gsub!(/(Re:\s)+?|Re\[\d+\]:\s/i, "")}"
  end
  return result
 end

As a result, we get rid of the terrible "Re: Re: Re:" or "Re [5]: Re: Re: Re [2]"