{"ScriptPreparationCode":"var url1 = \u0022https://localhost:3000/test?key1=value1\u0026key2=value2#test\u0022;\r\n\r\nconst urlPattern = /^(https?:\\/\\/[^\\/?#]\u002B[^?#]*)?(?:\\?([^#]*))?(?:#([^?]*))?(?:\\?([^#]*))?/;\r\n\r\nfunction extractParts1(inputUrl) {\r\n const match = inputUrl.match(urlPattern);\r\n if (!match) return null;\r\n\r\n let url = match[1] || null;\r\n let searchParams = match[2] || null;\r\n let fragment = match[3] || null;\r\n // If there are query parameters after the fragment\r\n if (match[4]) {\r\n searchParams = searchParams ? searchParams \u002B \u0027\u0026\u0027 \u002B match[4] : match[4];\r\n }\r\n\r\n return {\r\n url,\r\n searchParams,\r\n fragment\r\n };\r\n}\r\n\r\n\r\nfunction extractParts2(inputUrl) {\r\n // Parse basic URL and fragment\r\n const [base, fragmentQuery] = inputUrl.split(\u0027#\u0027);\r\n \r\n // Parse URL and search parameters from base\r\n let [url, searchParams] = base.split(\u0027?\u0027);\r\n\r\n // If there\u0027s fragment data, check for additional query parameters\r\n let fragment = null;\r\n let extraSearchParams = null;\r\n if (fragmentQuery) {\r\n if (fragmentQuery.includes(\u0027?\u0027)) {\r\n [fragment, extraSearchParams] = fragmentQuery.split(\u0027?\u0027);\r\n searchParams = searchParams ? \u0060${searchParams}\u0026${extraSearchParams}\u0060 : extraSearchParams;\r\n } else {\r\n fragment = fragmentQuery;\r\n }\r\n }\r\n\r\n return {\r\n url,\r\n searchParams: searchParams || null,\r\n fragment: fragment || null\r\n };\r\n}\r\n\r\n\r\nfunction extractParts3(inputUrl) {\r\n const queryIndex = inputUrl.indexOf(\u0027?\u0027);\r\n const hashIndex = inputUrl.indexOf(\u0027#\u0027);\r\n\r\n const hasQueryBeforeHash = queryIndex !== -1 \u0026\u0026 (hashIndex === -1 || queryIndex \u003C hashIndex);\r\n\r\n const url = hasQueryBeforeHash ? inputUrl.substring(0, queryIndex) : (hashIndex !== -1 ? inputUrl.substring(0, hashIndex) : inputUrl);\r\n\r\n let searchParams = null, fragment = null;\r\n\r\n if (hashIndex !== -1) {\r\n const fragmentWithQuery = inputUrl.substring(hashIndex \u002B 1);\r\n const fragmentQueryIndex = fragmentWithQuery.indexOf(\u0027?\u0027);\r\n\r\n if (fragmentQueryIndex !== -1) {\r\n fragment = fragmentWithQuery.substring(0, fragmentQueryIndex);\r\n searchParams = fragmentWithQuery.substring(fragmentQueryIndex \u002B 1);\r\n if (hasQueryBeforeHash) {\r\n searchParams = inputUrl.substring(queryIndex \u002B 1, hashIndex) \u002B \u0027\u0026\u0027 \u002B searchParams;\r\n }\r\n } else {\r\n fragment = fragmentWithQuery;\r\n }\r\n }\r\n\r\n if (hasQueryBeforeHash \u0026\u0026 !searchParams) {\r\n searchParams = hashIndex !== -1 ? inputUrl.substring(queryIndex \u002B 1, hashIndex) : inputUrl.substring(queryIndex \u002B 1);\r\n }\r\n\r\n return {\r\n url,\r\n searchParams: searchParams || null,\r\n fragment: fragment || null\r\n };\r\n}\r\n\r\nfunction extractParts4(inputUrl) {\r\n return new URL(inputUrl);\r\n}","TestCases":[{"Name":"patern 1","Code":"extractParts1(url1);","IsDeferred":false},{"Name":"patern 2","Code":"extractParts2(url1);","IsDeferred":false},{"Name":"patern 3","Code":"extractParts3(url1);","IsDeferred":false},{"Name":"patern 4","Code":"extractParts4(url1);","IsDeferred":false}]}