How to get just the image name from string that may have one or more images in javascript? -
i have name of image string have in message. have types of strings:
s1 = "bla bla name1.jpg bla bla name2.jpg bla bla"
and
s2 = "bla bla name1.jpg bla bla"
and have 2 problems:
for function like:
function getphotoname(message){ var photoregex = /.* (.*jpe?g).*/i; // extension may jpg, jpeg, jpg , jpeg return message.replace(photoregex, "$1"); }
it returns name correct s2
case , s1
case result second name.
for function of type:
function getphotoname(message){ var photoregex = /.* (.*jpe?g).* (.*jpe?g).*/i; // extension may jpg, jpeg, jpg , jpeg return message.replace(photoregex, "$1"); }
the result ok s1
case, s2
case, result name , text before ("bla bla name1.jpg"
).
how make work?
try match()
:
var names = "bla bla name1.jpg bla bla name2.jpg bla bla".match(/(\w+\.jpe?g)/gi) //["name1.jpg", "name2.jpg"] var names = "bla bla name1.jpg bla bla".match(/(\w+\.jpe?g)/gi)// ["name1.jpg"] var names = "bla bla image.jpeg bla bla".match(/(\w+\.jpe?g)/gi)// ["image.jpeg"]
Comments
Post a Comment