Try new RegEx for creating links

This commit is contained in:
rugk 2018-07-01 15:13:24 +02:00
parent 8386141322
commit 119c3931cc
No known key found for this signature in database
GPG key ID: 05D40A636AFAB34D
3 changed files with 4 additions and 3 deletions

View file

@ -144,8 +144,9 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
*/
me.urls2links = function(html)
{
// URL part of RegEx: https://regex101.com/r/h4ACei/4
return html.replace(
/(((http|https|ftp):\/\/[\w?=&.\/-;#@~%+*-]+(?![\w\s?&.\/;#~%"=-]*>))|((magnet):[\w?=&.\/-;#@~%+*-]+))/ig,
/((https?|ftp):\/\/(([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+(:([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+)?@)?((([a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*[a-z][a-z0-9-]*[a-z0-9]|((\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5]))(:\d+)?)(((\/+([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)*(\?([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?)?)?(#([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?)|((magnet):[\w?=&.\/-;#@~%+*-]+)/ig,
'<a href="$1" rel="nofollow">$1</a>'
);
};