I have an email message which looks like this:
Hey how are you?
On Saturday [email protected] wrote:
> something
> On Friday [email protected] wrote:
>> previous thing
How would I remove the lines that start with >
as well as lines that include [email protected] wrote
Should I even keep the "someone wrote" part as that could remove legitimate lines, maybe only removing that line if it's the last line.
I'm trying this out:
message_filtered = message_txt.to_s.split("\n").each do |m|
if m[0] != ">" then
return m
end
end
puts message_filtered
I could push m
to an array and then join that array with \n
but i'm trying a shorter way.
Try
message_filtered = message_txt.lines.reject { |line|
line[0] == '>' || line =~ YOUR_EMAIL_REGEXP
}.join('\n')
To remove lines that start with >
you can use:
message_filtered = message_txt.gsub(/(^>.+)/, '') # should work but not tested
my proposition:
message_filtered = '';
message_txt.to_s.lines {|line| message_filtered << line unless line[0] == '>' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With