What is a safe an efficient way to filter links from user inputted data, and create an anchor link that is then used in the html. Like how when writing a question, and you copy-paste a link, it automatically becomes an anchor link.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use Gruber’s regular expression to find the URIs.
Result:
Now the Gruber regex will actually match partial URIs such as
www.stackoverflow.com(this is missing thehttp://scheme), which won’t work when you just stick it into an anchor tag. You can write a function that checks for that and adds it where necessary, then use that to do the replacement: