I have a string in my code that I receive that contains some html tags. It is not part of the HTML page being displayed so I cannot grab the html tag contents using the DOM (i.e. document.getElementById('tag id').firstChild.data);
So, for example within the string of text would appear a tag like this:
<span id='myQty'>12</span>
My question is how would I use a regular expression to access the '12' numeric digit in this example? This quantity could be any number of digits (i.e. it is not always a double digit).
I have tried some regular expressions, but always end up getting the full span tag returned along with the contents. I only want the '12' in the example above, not the surrounding <span>
tag. The id of the <span>
tags will always be 'myQty' in the string of text I receive.
Thanks in advance for any help!
var testfunction = function (input) {
var regvar = new RegExp(/^(<span id\='myQty'>\w+<\/span>)$/);
if (regvar.test(input) === true) {
input = input.slice(6, input.length - 7);
}
return input;
}