Regular Expression to return the contents of a HTML tag received as a string of text

Posted by Nathan Hernandez on Stack Overflow See other posts from Stack Overflow or by Nathan Hernandez
Published on 2010-05-10T17:37:29Z Indexed on 2010/05/10 17:44 UTC
Read the original article Hit count: 218

Filed under:
|

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: 12

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 tag. The id of the tags will always be 'myQty' in the string of text I receive.

Thanks in advance for any help!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex