This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby-1.9.2-p136 :057 > def linkify_it(txt) | |
ruby-1.9.2-p136 :058?> safe_text = ERB::Util::h(txt) | |
ruby-1.9.2-p136 :059?> safe_text.gsub(/(^|\s)(https?:\/\/([^\s\/]*)\S*)(\s|$)/i) {|m| puts "safe txt: match '#{m}', $1 '#{$1}', $2 '#{$2}', $3 '#{$3}', $4 '#{$4}'"} | |
ruby-1.9.2-p136 :060?> txt.gsub(/(^|\s)(https?:\/\/([^\s\/]*)\S*)(\s|$)/i) {|m| puts "unsafe txt: match '#{m}', $1 '#{$1}', $2 '#{$2}', $3 '#{$3}', $4 '#{$4}'"} | |
ruby-1.9.2-p136 :061?> end | |
=> nil | |
ruby-1.9.2-p136 :062 > linkify_it(a) | |
safe txt: match ' hTTp://google.com ', $1 '', $2 '', $3 '', $4 '' | |
unsafe txt: match ' hTTp://google.com ', $1 ' ', $2 'hTTp://google.com', $3 'google.com', $4 ' ' | |
=> "try thisit is fun" |