I have been using the following, which works for all my test cases, as well as fixes any issues where it would trigger at the end of a sentence preceded by a full-stop (end.
), or where there were single character initials, such as 'C.C. Plumbing'.
The following regex contains multiple {2,}
s, which means two or more matches of the previous pattern.
((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]{2,}\.([a-zA-Z0-9\&\.\/\?\:@\-_=#]){2,}
Matches URLs such as, but not limited to:
Does not match non-URLs such as, but not limited to:
- C.C Plumber
- A full-stop at the end of a sentence.
- Single characters such as
a.b
or x.y
Please note: Due to the above, this will not match any single character URLs, such as: a.co
, but it will match if it is preceded by a URL scheme, such as: http://a.co
.