string str contains somewhere within it http://www.example.com/ followed by 2 digits and 7 random characters (upper or lower case). One possibility is http://www.example.com/45kaFkeLd or http://www.example.com/64kAleoFr. So the only certain aspect is that it always starts with 2 digits.
I want to retrieve “64kAleoFr”.
var url = str.match([regex here]);
The regex you’re looking for is
/[0-9]{2}[a-zA-Z]{7}/.Note that on the second line, I use the good old
.match()trick to make sure noTypeErroris thrown when no match is found. Once this snippet has executed,matchwill either be the empty string ('') or the value you were after.