I am trying to replace <h[num] id="....">Header</h[num]>
with h[num]. Header
This is what I have tried, but I cannot get it to work:
html.replace('/<h(\d+).*?>([\s\S]*?)<\/h.*?>/', "h$1. $2");
I am trying to replace <h[num] id="....">Header</h[num]>
with h[num]. Header
This is what I have tried, but I cannot get it to work:
html.replace('/<h(\d+).*?>([\s\S]*?)<\/h.*?>/', "h$1. $2");
Actually, it can.
Check the example in http://jsfiddle.net/cLHk3/
function replaceHTML(){
var elements = document.querySelectorAll('h1,h2,h3,h4,h5');
Array.prototype.slice.call(elements).forEach(function(element){
var text = element.tagName+'. Header';
element.parentNode.insertBefore(document.createTextNode(text),element);
element.parentNode.insertBefore(document.createElement('br'),element);
element.parentNode.removeChild(element);
})
}
The answer to this was the following:
var html = <h1 id="....">Header</h1>
var re = /^<h(\d+)[\s\S]*?>([\s\S]*)<\/h(\d+)>$/;
html.replace(re, "h$1. $2");