From 1002e0baeb8f56cd47ecbe312432e9d9b8d29891 Mon Sep 17 00:00:00 2001 From: kristol07 Date: Tue, 7 Mar 2023 13:51:46 +0800 Subject: [PATCH] improve regex for url parse --- packages/puppeteer-parse/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/puppeteer-parse/index.js b/packages/puppeteer-parse/index.js index f84b5534a..26dc7eef2 100644 --- a/packages/puppeteer-parse/index.js +++ b/packages/puppeteer-parse/index.js @@ -402,13 +402,13 @@ function tryParseUrl(urlStr) { return null; } - // a regular expression to match URLs - var regex = /(https?:\/\/[^\s]+)/g; + // a regular expression to match all URLs + const regex = /(https?:\/\/[^\s]+)/g; - var match = regex.exec(urlStr); + const matches = urlStr.match(regex); - if (match) { - return match[1]; + if (matches) { + return matches[0]; // only return first match } else { return null; }