dwilbank
dwilbank

Reputation: 2520

regex is right - yet match returns nil - why?

Good sirs.

I seem to have a decent regex to capture the url I want...

So how am I using it wrong?

2.0.0-p451 :237 > resbody
 => "{"provider_url": "http://www.popsci.com", ...
2.0.0-p451 :240 > resbody.match(/"thumbnail_url":"([^"]*)"/)
 => nil
2.0.0-p451 :241 > resbody.scan(/"thumbnail_url":"([^"]*)"/)
 => []
2.0.0-p451 :242 > resbody[/"thumbnail_url":"([^"]*)"/,1]
 => nil

Upvotes: 0

Views: 45

Answers (1)

spickermann
spickermann

Reputation: 106972

That string looks like JSON. Therefore the following should return the what you need:

require 'json'
JSON.parse(resbody)['thumbnail_url']

Upvotes: 1

Related Questions