manish nautiyal
manish nautiyal

Reputation: 2594

how to remove single quotes(') in ruby on rails

@content = "<p><span style=\"font-family: 'trebuchet ms', 'geneva'; font-size: 'large';\">Helo's</span></p>"

I want to remove single quotes (') from <style> but not from the Helo's. Right now I'm using this but this remove all the single quotes(').

@content.gsub(/'/,"")

Upvotes: 1

Views: 2053

Answers (2)

Justin Ko
Justin Ko

Reputation: 46846

You could do:

@content.gsub(/style=".+?"/){ |x| x.gsub("'", '') }

This would remove the single quotes from the style attributes.

Upvotes: 2

simonmenke
simonmenke

Reputation: 2880

Seems like you are going to need to parse the HTML with something like nokogiri. Only then you will be able to replace the text content of the tags.

Upvotes: 1

Related Questions