How to extract hyperlink from string

0
Hello All, Getting below string from API response,i need to extract hyperlink from string.   String:-  1. [TEST_Systems_Manual](https://test.blob.core.windows.net/raw/DET_IM_3TM5_]Systems_Manual.pdf?st=2024-03-08T17:02:24Z&se=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRCMS0OCPSBc1NhAjIPE%3D) - [491](https://test.blob.core.windows.net/raw/DET_IM_3TM5_Manual.pdf?st=2024-03-08T17:02:24Z&de=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRXa1O9AxHW8IPE%3D#page=491)(https://sa003stdirtest.blob.core.windows.net/raw/DET_IM_3TM5_]Systems_Manual.pdf?st=2024-03-08T17:02:24Z&se=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRCMS0OCcIPE%3D) - [492](https://ditest.blob.core.windows.net/raw/DET_IM_3TM5.pdf?st=2024-03-08T17:02:24Z&se=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRCMS0OCD#page=492)   Need below hyperlink from above string. https://test.blob.core.windows.net/raw/DET_IM_3TM5_Manual.pdf?st=2024-03-08T17:02:24Z&de=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRXa1O9AxHW8IPE%3D#page=491   https://ditest.blob.core.windows.net/raw/DET_IM_3TM5.pdf?st=2024-03-08T17:02:24Z&se=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRCMS0OCD#page=492   there may be many hperlink on string,tried with Substring,find function but not working please suggest.
asked
1 answers
0
const string = "(https://test.blob.core.windows.net/raw/DET_IM_3TM5_]Systems_Manual.pdf?st=2024-03-08T17:02:24Z&se=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRCMS0OCPSBc1NhAjIPE%3D) - [491](https://test.blob.core.windows.net/raw/DET_IM_3TM5_Manual.pdf?st=2024-03-08T17:02:24Z&de=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRXa1O9AxHW8IPE%3D#page=491)(https://sa003stdirtest.blob.core.windows.net/raw/DET_IM_3TM5_]Systems_Manual.pdf?st=2024-03-08T17:02:24Z&se=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRCMS0OCcIPE%3D) - [492](https://ditest.blob.core.windows.net/raw/DET_IM_3TM5.pdf?st=2024-03-08T17:02:24Z&se=2138-04-07T09:02:24Z&sp=r&spr=https&sv=2023-11-03&sr=b&sig=MRCMS0OCD#page=492)";


const regex = /(?:https?|ftp):\/\/[\n\S]+?(?=\s|$|\)|\()|www\.[\n\S]+?(?=\s|$|\)|\()|\[\d+\]\((.*?)\)/gi;

// Array to store matched URLs
const urls = [];

// Match URLs and push them to the array
let match;
while ((match = regex.exec(string)) !== null) {
  // Extract only the URLs contained within [number](url) pattern
  if (match[1]) {
    urls.push(match[1]);
  }
}
console.log(urls);

 

Replace string variable by your string attribute.

You can use above code in javascript action.

 

Hope this will work.

 

answered