3

I have a Rails app that is reading in RSS feeds using the simple_feed gem. However, some of the feeds don't read in correctly - namely, some of the titles have:

`‘`

or

`’`

instead of: "

My titles read in as:

i.title

and I was thinking that gsub can fix this easily, but I was have trouble making it work. I tried:

i.title.gsub(%r[‘]/, '"')

which I'm not even sure would work, but it commented out the line after the #.

Then I tried:

i.title.gsub(%r["‘"]/, '*')

which results in:

C:/Sites/foo/app/views/bar/show.html.erb:20: syntax error, unexpected ','
...( i.title.gsub(%r["‘"]/, '*') )

I haven't really used gsub before, I was trying to work off these examples. Can something please help me figure out what I'm doing wrong?

yellowreign
  • 3,528
  • 8
  • 43
  • 80

1 Answers1

7

Try with

i.title.gsub("‘", '"')

or with

i.title.gsub(/‘/, '"')
rorra
  • 9,593
  • 3
  • 39
  • 61
  • Thanks Rorra, that works. I've found that sometimes ’ also appears, so I have multiple strings to look for (I edited my question - I had a typo before where I said ‘ or ‘ appears instead of saying ‘ or ’ appears). How do I change the syntax to reflect this? – yellowreign Mar 03 '13 at 21:05
  • Sorry, I should have searched first. I found this answer and just ended up adding another .gsub (ie str.gsub.gsub) http://stackoverflow.com/questions/8132492/ruby-multiple-string-replacement – yellowreign Mar 03 '13 at 21:11