Ask coding questions

← Back to all posts
How to detect links in chat
indigiz (9)

Edit here: https://replit.com/join/ixccdkzl-indigiz

Im wondering, when you send a message, if u send a link, how do u detect a hyperlink?

Answered by SixBeeps (5234) [earned 5 cycles]
View Answer
Comments
hotnewtop
SixBeeps (5234)

You could use some RegEx pattern matching for that. You'd find all the URLs using a Regular Expression, then replace them all with <a> tags.

indigiz (9)

@SixBeeps no what i mean as link detecting is when somebody sends a link, it highlights the link, and makes it so you can click the link to go to the output url (hyperlink).

SixBeeps (5234)

@indigiz Yes, I know what you mean, and my solution would do exactly that.

You could choose to do link detection on the client or server side, but I'd suggest doing it on the client side to make sanitation easier. When the client receives a message, replace each RegEx match with a hyperlink, <a>, that leads to the matched text.

indigiz (9)

@SixBeeps can u just edit my code so that if server recieved link, itll make hyperlink? Im kinda new to this