There was a requirement of hiding all the wesite URL in a message except for a particular one. While looking for a solution I came across a particular solution which I think might help other .
params[:meal_note] = params[:meal_note].gsub(/(?!\S+mealsharing\.com)((?<!\S)(((f|ht){1}tp[s]?:\/\/|(?<!\S)www\.)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+))/,'(website hidden)')
Here params[:meal_note] is the text that might contain website URL. What exactly we are doing with the above regex is looking for all website url except mealsharing.com and replacing it with '(website hidden)' string so that no one on the site can add other site reference.
Hope this help some.
0 Comment(s)