I want to extract image name from img tag with regex in javascript. My problem is that console.log() throws Exception:TypeError: pattern.exec is not a function.
JS:
$("label.btn-danger").on('click',function(e){
e.preventDefault();
var src = $(this).parents("label").find("img").attr("src");
var pattern = "/\/([A-Z0-9_-]{1,}\.(?:png|jpg|gif|jpeg))/ig";
var result = pattern.exec(src)
console.log(result);
});
var pattern = /\/([A-Z0-9_-]{1,}\.(?:png|jpg|gif|jpeg))/ig;[0]element will be full matched input and[1]will be first matched group..attr("src")toprop("src")and see what happens