my code is:
var st="man myfile=l/p/nm.mp3 yourfile=/o/mj/nnc.mp3 ou p";
var patt=/myfile.[\W|\w]*.mp3\s/;
var s=patt.exec(st);
var s2=s.slice(3,4);
alert(s2);
but slice() gives me nothing and substr() method gives me an error:
Object doesn't support this method
Why?
Fabricio is right. Your variable s is a RegExp object. To access the substring you'll need to do:
var s2 = s[0].substr(3,4);
jsFiddle here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With