■もったいないので載っけちゃいます
h4タグにspot+連番という形で連番のIDを振っていくJavaScriptです。ちなみにこのケースでは正規表現の後方参照でh4タグの後に数字が入っている場合のみ置換対象としています。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無題ドキュメント</title> <script type="text/javascript"> window.onload = function(){ document.getElementById('execute').onclick = function(){ var txt = document.getElementById('original').value; var tmpAry = txt.split(/<h4>(?=[0-9])/); for(var i = 1; i<(tmpAry.length); i++){ tmpAry[i] = '<h4 id="spot' + i + '">' + tmpAry[i]; } //alert(txt); document.getElementById('converted').value = tmpAry.join(''); } } </script> </head> <body> <form action=""> <textarea id="original" name="original" cols="80" rows="10"></textarea> <textarea id="converted" name="converted" cols="80" rows="10"></textarea> <p><input type="button" id="execute" value="execute" /></p> </form> </body> </html>
■コメント
プログラムって素敵。みんなの負荷が軽くなる。自分の負荷も軽くなる。JavaScript万歳!