Try
var text = '<div class="product-price-container"> <a href="/rca-32-class-720p-60hz-led-hdtv-with-built-in-dvd-player-led32b30rqd/226660215" class="product-link subject-price" data-external-product-id="05771292000P"> <span class="save-story-box">'
text.match(/data-external-product-id="([0-9A-Za-z]+)"/)[1]
match(...)
returns an array with the whole match as the first element and your group match (i.e. [0-9A-Za-z]+
) as the second element. If you can trust the source from where you get the text, you can also use jQuery (here the code on jsFiddle):
var text = '<div class="product-price-container"> <a href="/rca-32-class-720p-60hz-led-hdtv-with-built-in-dvd-player-led32b30rqd/226660215" class="product-link subject-price" data-external-product-id="05771292000P"> <span class="save-story-box">'
var id = $($.parseHTML(text)).find("a").attr("data-external-product-id")
alert(id) // 05771292000P
Please have in mind, that everyone can execute malicious JavaScript with $.parseHTML
if he has control over the parsed text. So only use the above solution, if you have control over the parsed text.