Can anyone assist with extracting a specific string using regex in TypeScript?
I have the following URL: https://test.io/content/storage/id/urn:aaid:sc:US:8eda16d4-baba-4c90-84ca-0f4c215358a1;revision=0?component_id=e62a5567-066d-452a-b147-19d909396132
I need to extract this string: urn:aaid:sc:US:8eda16d4-baba-4c90-84ca-0f4c215358a1, which always starts with "urn" and ends with a letter or number.
Could someone please provide guidance on how to achieve this using typescript?
I attempted the following code but received a null value. Any suggestions are appreciated!
function extractAssetIdFromUrl(url: string) {
// Regular expression to match the desired pattern
const regex = /urn[\w-]+/;
// Use the regex to find the match in the URL
const match = url.match(regex);
// Check if there is a match and return it, otherwise return null
return match ? match[0] : null;
}