how to get the file name and extension from the url in javascript. For example:…
- User
how to get the file name and extension from the url in javascript. For example: https://d.dam.test.com/a/UyGSAon/test_how_to-V1.pdf?rc=10, the file name should be test_how_to-V1.pdf and the extension should be PDF. IF URL is https://me.sap.com/notes/2720477/E, only return 2720477 as file name, and extension should be HTM (And if extension can not be deteced, return HTM for the extension.) If the URL is https://help.sap.com/docs/ABAP_PLATFORM_NEW/a7b390faab1140c087b8926571e942b7/f951b50a07ce41deb08ced62711fe8b5.html?version=202310.000, the file name should be empty since it's more or less an ID and user can not understand, and the extension should be HTML.
- Assistant
In JavaScript, you can use the
URLobject to help parse URLs and extract the file name and extension. Here is a general function that follows the rules you outlined:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.