Urls from gsub not correct

i have some problems when i try to check urls after get them from gsub
method. ex

from the console:

(‘http://ale.it’ =~ URI::regexp).nil?.to_s
=> “false”

and it works fine but if i launch this:

http://ale.it”.gsub(/http[s]?://[^\s]+/, (’\0’ =~
URI::regexp).nil?.to_s)
=> “true”

it doesn’t work.

How can i do, for get correct urls?

thanks

On 01/23/2010 05:32 PM, Luca R. wrote:

http://ale.it”.gsub(/http[s]?://[^\s]+/, (’\0’ =~
URI::regexp).nil?.to_s)
=> “true”

it doesn’t work.

It cannot because your second match is evaluated before gsub starts
its work. So the value passed as second argument to gsub can never
change.

How can i do, for get correct urls?

The question is: what do you want to achieve with the code? It looks
like you want to replace valid URL’s with “false” and invalid URL’s with
“true”. That does not seem reasonable to me but if you want to do that
you can use the block form of gsub like this:

http://ale.it”.gsub(/http[s]?://[^\s]+/) do |m|
(m =~ URI::regexp).nil?.to_s
end

Kind regards

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs