Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Rust

r"
\[(?:http://|https://)*(?:\w+\.)*(\w+(?:\.(?:com|org|net|edu|gov|info|biz|io|co|app|co|uk|de|jp|ca|dev|app|gg))+)]\((?:http://|https://)(?:\w+\.)+\w+(?:/\w+)*\)
"
gm

Description

This regex catches markdown links where the display text is also a link, like this: [example.com](https://malicious.link) in order to prevent people getting tricked and clicking on a link that isn't what it says it is.

See the test string for a much longer explanation with examples.

Submitted by Osh - 7 months ago (Last modified 7 months ago)