From 3aabba8b76b2d6be3de0666c6c57df388d3f7589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Colombaro?= Date: Fri, 22 Sep 2017 00:37:26 +0200 Subject: [PATCH 1/2] more functional regex for url parsing Based on stephenhay work as seen on https://mathiasbynens.be/demo/url-regex --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ef14f73..88ab2cf 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const createHtmlElement = require('create-html-element'); // Capture the whole URL in group 1 to keep string.split() support -const urlRegex = () => (/((?:https?(?::\/\/))(?:www\.)?[a-zA-Z0-9-_.]+(?:\.[a-zA-Z0-9]{2,})(?:[-a-zA-Z0-9:%_+.~#?&//=@]*))/g); +const urlRegex = () => (/((?:https?(?::\/\/))[^\s/$.?#].[^\s]*)/ig); // Get element as string const linkify = (href, options) => createHtmlElement({ From e96df172b41caa95f146df1cf530e22bd7e7db55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Colombaro?= Date: Mon, 25 Sep 2017 19:56:10 +0200 Subject: [PATCH 2/2] avoid too long match when parentheses englobing --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 88ab2cf..996cc73 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const createHtmlElement = require('create-html-element'); // Capture the whole URL in group 1 to keep string.split() support -const urlRegex = () => (/((?:https?(?::\/\/))[^\s/$.?#].[^\s]*)/ig); +const urlRegex = () => (/((?:https?(?::\/\/))[^\s/$.?#].[^\s()]*)/ig); // Get element as string const linkify = (href, options) => createHtmlElement({