SQLの窓

2010年08月27日


JS : 正規表現置換基本テスト

HTML の記述そのものを、HTML 上で表現する為の文字列の置換のテストを
行う HTML( +JavaScript ) です。

※ /g で全て置換する事が解ると思います。
※ サンプルは、charset=euc-jp であることに注意してください





<html>
<head>
<META http-equiv="Content-type" content="text/html; charset=euc-jp" />
<title>JavaScript 正規表現置換基本テスト</title>
<script type="text/javascript">

function act_replace( ev ) {

	txt = document.getElementsByName("text")[0].value;

	txt = txt.replace( /&/g, "&amp;" );
	txt = txt.replace( /</g, "&lt;" );
	txt = txt.replace( />/g, "&gt;" );

	document.getElementById("area").innerHTML = txt;

}

function act_replace_no( ev ) {

	txt = document.getElementsByName("text")[0].value;

	document.getElementById("area").innerHTML = txt;

}

function act_replace_nog( ev ) {

	txt = document.getElementsByName("text")[0].value;

	txt = txt.replace( /&/, "&amp;" );
	txt = txt.replace( /</, "&lt;" );
	txt = txt.replace( />/, "&gt;" );

	document.getElementById("area").innerHTML = txt;

}

</script>

</head>
<body>

<textarea
	name="text"
	style='width:400px;height:100px;'
>&lt;input type="text"&gt;
&lt;input type="text"&gt;</textarea>
<br />
<input type="button" value="置換する" onclick="act_replace(event);">
<input type="button" value="そのまま" onclick="act_replace_no(event);">
<input type="button" value="g無し置換" onclick="act_replace_nog(event);">
<br />
<pre id="area"></pre>


</body>
</html>



【JavaScript 正規表現の最新記事】
posted by lightbox at 2010-08-27 15:44 | JavaScript 正規表現 | このブログの読者になる | 更新情報をチェックする
container 終わり



フリーフォントで簡単ロゴ作成
フリーフォントでボタン素材作成
フリーフォントで吹き出し画像作成
フリーフォントではんこ画像作成
ほぼ自由に利用できるフリーフォント
フリーフォントの書体見本とサンプル
画像を大きく見る為のウインドウを開くボタンの作成

CSS ドロップシャドウの参考デモ
イラストAC
ぱくたそ
写真素材 足成
フリーフォント一覧
utf8 文字ツール
右サイド 終わり
base 終わり