-2

I want to extract "stringtoextract" below I can't see why it doesn't work: https://jsfiddle.net/dwbnj6z7/

  let url = 'https://mystuff.com/test/varstring/stringtoextract?id=test3'
  let regex = /https:\/\/stuff.com\/test\/varstring\/.+\/(.+)?.+/
  var match = regex.exec(url);
  alert(match[1]); 
user310291
  • 36,946
  • 82
  • 271
  • 487

1 Answers1

1

Try out this code. I've changed the regex a bit:

let url = 'https://example.com/test/varstring/stringtoextract?id=test3'
let regex = /https:\/\/example\.com\/test\/varstring\/(.+)\?.+/
var match = regex.exec(url);
console.log(match[1]); 
blaumeise20
  • 2,148
  • 8
  • 26