From 7d3115c92043a75b7d9a759cb2b9e3e20232a7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20V=C3=A9lez=20Vidal?= Date: Thu, 10 Aug 2023 13:53:27 +0200 Subject: [PATCH] enhance regular expression to support optional subpath --- app/utils/helpers.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/utils/helpers.ts b/app/utils/helpers.ts index d464492ff..715951d38 100644 --- a/app/utils/helpers.ts +++ b/app/utils/helpers.ts @@ -174,13 +174,16 @@ export function isMainActivity() { * // Input: https://example-something.com => Result: example-something * // Input: http://192.168.1.1 => Result: 192.168.1.1 * // Input: https://127.0.0.1:3000 => Result: 127.0.0.1 + * // Input: https://subdomain.example.com/api => subdomain.example.com/api + * // Input: http://localhost:8080/app/v1 => localhost:8080/app/v1 */ export function extractDomain(input: string) { - const regex = /^(https?:\/\/)?([\w.-]+)(:\d+)?$/; + const regex = /^(https?:\/\/)?([\w.-]+)(:\d+)?(\/\S*)?/; const match = input.match(regex); - if (match && match[2]) { - return match[2].replace(/[\W.]/g, ''); + if (match) { + const modifiedString = match[2] + (match[4] || ''); + return modifiedString; } return '';