JSFiddle - React, Tailwind, and code Playground
JavaScript
let url = 'https://mydomain.com/test/varstring/stringtoextract?id=test3'
let regex = /https:\/\/mydomain.com\/test\/varstring\/.+\/(.+)?.+/
var match = regex.exec(url);
alert(match[1]);
let url = 'https://mydomain.com/test/varstring/stringtoextract?id=test3'
let regex = /https:\/\/mydomain.com\/test\/varstring\/.+\/(.+)?.+/
var match = regex.exec(url);
alert(match[1]);