window.onerror = function() { if (document.fm.chk.checked) { alert("* エラー *\n\n正規表現に誤りがあります。"); return true; } } function replaceStr(){ var str = document.fm.input.value; var str_s = document.fm.text1.value; var str_r = document.fm.text2.value; var reg; if(document.fm.chk.checked){ reg = new RegExp(str_s, "g"); document.fm.output.value = str.replace(reg, str_r); } else { document.fm.output.value = str.split(str_s).join(str_r); } }