Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your best bet is to use <code>innerText</code> or <code>textContent</code> to get at the text without the tags and then just use the regex <code>/\d/g</code> to get the numbers.</p> <pre><code>function digitsInText(rootDomNode) { var text = rootDomNode.textContent || rootDomNode.innerText; return text.match(/\d/g) || []; } </code></pre> <p>For example,</p> <pre><code>alert(digitsInText(document.body)); </code></pre> <p>If your HTML is not in the DOM, you can try to strip the tags yourself : <a href="https://stackoverflow.com/questions/5002111/javascript-how-to-strip-html-tags-from-string">JavaScript: How to strip HTML tags from string?</a></p> <hr> <p>Since you need to do a replacement, I would still try to walk the DOM and operate on text nodes individually, but if that is out of the question, try</p> <pre><code>var HTML_TOKEN = /(?:[^&lt;\d]|&lt;(?!\/?[a-z]|!--))+|&lt;!--[\s\S]*?--&gt;|&lt;\/?[a-z](?:[^"&gt;']|"[^"]*"|'[^']*')*&gt;|(\d+)/gi; function incrementAllNumbersInHtmlTextNodes(html) { return html.replace(HTML_TOKEN, function (all, digits) { if ("string" === typeof digits) { return "" + (+digits + 1); } return all; }); } </code></pre> <p>then</p> <pre><code>incrementAllNumbersInHtmlTextNodes( '&lt;b&gt;123&lt;/b&gt;Hello, World!&lt;p&gt;I &lt;3 Ponies&lt;/p&gt;&lt;div id=123&gt;245&lt;/div&gt;') </code></pre> <p>produces</p> <pre><code> '&lt;b&gt;124&lt;/b&gt;Hello, World!&lt;p&gt;I &lt;4 Ponies&lt;/p&gt;&lt;div id=123&gt;246&lt;/div&gt;' </code></pre> <p>It will get confused around where special elements like <code>&lt;script&gt;</code> end and won't recognize digits that are entity encoded, but should work otherwise.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload