I am trying to extract hash value from an magnet link but it returns undefined
var tesst = \"magnet:?xt=urn:btih:2B78EDFDDC87DC9605FB285997A80B787888C19
You need to include [a-z\d]{40} part inside a capturing group and you don't need to escape & symbol, because it isn't a regex meta character.
[a-z\d]{40}
&
> var test = tesst.match(/magnet:\?xt=urn:btih:([a-z\d]{40})&/im); undefined > console.log(test[1]) 2B78EDFDDC87DC9605FB285997A80B787888C194