Use regex with match () function :
var str = "... width=600 height=1200 ...",
width = str.match(/\bwidth=(\d+)/);
if (width)
alert(width[1]);
The proposed regular expression searches for the word boundary ( \b), followed by a literal string width=, followed by 1 or more digits, which are also written as a subexpression ( (\d+)). This sub-expression capture is added to the array returned by the match.
source
share