Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Hiding all the URL in a text except a particular one

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 194
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: