Skip to content
Snippets Groups Projects
Commit 5ff3834b authored by Joscha Schmiedt's avatar Joscha Schmiedt
Browse files

Add a better regex for linkify

parent 7060ed2c
No related branches found
No related tags found
2 merge requests!131FIX: error in regexp to match URLs,!128F 344 extern linkify absorbs commas etc into link adress
Checking pipeline status
...@@ -68,7 +68,10 @@ var cosmetics = new function () { ...@@ -68,7 +68,10 @@ var cosmetics = new function () {
* @returns {string} text with <a> elements instead of raw links * @returns {string} text with <a> elements instead of raw links
*/ */
function linkify_string(text) { function linkify_string(text) {
const match_url_regex = /https?:\/\/[^\s]*\b(?![,:;?!])/gi; // const match_url_regex = /https?:\/\/[^\s]*/g // original
// https://regexr.com helps you design regex
const match_url_regex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.?[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g
return text.replace(match_url_regex, function (href) { return text.replace(match_url_regex, function (href) {
var link_text = href; var link_text = href;
if (_link_cut_off_length > 4 && link_text.length > _link_cut_off_length) { if (_link_cut_off_length > 4 && link_text.length > _link_cut_off_length) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment