検索用語を入力
検索フォームを送信
my-Tool.com: 文字列とテキスト - 文字列とテキストを操作する。 - 置換
IPアドレス
MaximaPHP
正規表現テスタ
数学
ゲーム
ネットワーク
インターネットコード
日付と時間
文字列とテキスト
ワードドメイン
コードテスタ
ビーワイズビット
ランキン
質問と答え
僕について
フォーラム
AdManner
無料広告サイト
インドネシア語
英語
スプレッドシート
ケース変換
サイト抽出
EditArea
置換
統計
TinyMCE
置換
単語を他の単語で置換したりケースを変換したりする。正規表現もサポートする。
このツールは動くのにJavaScriptが必要。ブラウザーでJavaScriptを使用可能にしてください。
単語を検索する
:
例) 単語、単([^ ])
大・小文字区別しない
正規表現
これで置換する
:
例) フレーズ、フレ$1
大文字に
小文字に
逆に
ランダムに
置換 単語を他の単語で置換したりケースを変換したりする。正規表現もサポートする。 このテキストを自分のものに置き換えるだけで、どんな単語をも好きなように置換することができる。 ごゆっくり単語の置換を!
このツールを利用したほとんどのお客様は以下のツールも利用しました。
日付と時間
(15.8%),
Forum
(5.3%),
Source
(5.3%)
このツールのソースコードは以下に示す。
<?php /****************************************************************** * * Replacer, 単語を他の単語で置換したりケースを変換したりする。正規表現もサポートする。 * Copyright (C) 2006, Bowo Prasetyo * * http://www.my-tool.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation below, * * http://www.gnu.org/licenses/gpl.html#TOC1 * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * このプログラムはフリーソフトウェアです。あなたはこれを、以下のURLにフリーソフトウェ * ア財団によって発行された GNU 一般公衆利用許諾契約書の定める条件の下で * 再頒布または改変することができます。 * * http://www.gnu.org/licenses/gpl.html#TOC1 * * このプログラムは有用であることを願って頒布されますが、*全くの無保証* * です。商業可能性の保証や特定の目的への適合性は、言外に示されたものも含 * め全く存在しません。詳しくはGNU 一般公衆利用許諾契約書をご覧ください。 * * あなたはこのプログラムと共に、GNU 一般公衆利用許諾契約書の複製物を一部 * 受け取ったはずです。もし受け取っていなければ、フリーソフトウェア財団ま * で請求してください(宛先は the Free Software Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA)。 * *****************************************************************/ /** * 現在のツールを表示する * * @param int $depth インデックスページからどれぐらい深いか * @param string $qstring 親ツールのクエリー文字列 */ unset($find); if(isset($_POST['find'])) $find = trim(stripslashes($_POST['find'])); unset($nocase); if(isset($_POST['nocase'])) $nocase = $_POST['nocase']; unset($regexp); if(isset($_POST['regexp'])) $regexp = $_POST['regexp']; unset($replace); if(isset($_POST['replace'])) $replace = trim(stripslashes($_POST['replace'])); $method = 'text'; if(isset($_POST['method'])) $method = $_POST['method']; $conversion = 'upper'; if(isset($_POST['conversion'])) $conversion = $_POST['conversion']; $text = <<<EOT 置換 単語を他の単語で置換したりケースを変換したりする。正規表現もサポートする。 このテキストを自分のものに置き換えるだけで、どんな単語をも好きなように置換することができる。 ごゆっくり単語の置換を! EOT; if(isset($_POST['text'])) $text = trim(stripslashes($_POST['text'])); ?> <script src="/globals-ja.js"> </script> <script src="/replacer-ja.js"> </script> <noscript> このツールは動くのにJavaScriptが必要。ブラウザーでJavaScriptを使用可能にしてください。 </noscript> <form name="my_tool_form" method="POST" action=""> <table> <tr><td>単語を検索する</td><td>:</td> <td><input type="text" name="find" value="<?php echo $find ?>"> <span class="eg">例) 単語、単([^ ])<br> <input type="checkbox" name="nocase" value="yes" <?php echo $nocase=='yes'?'checked':'' ?>> 大・小文字区別しない <input type="checkbox" name="regexp" value="yes" <?php echo $regexp=='yes'?'checked':'' ?>> 正規表現 </td></tr> <tr><td>これで置換する</td><td>:</td> <td><input type="radio" name="method" value="text" <?php echo $method=='text'?'checked':'' ?>> <input type="text" name="replace" value="<?php echo $replace ?>"> <span class="eg">例) フレーズ、フレ$1</span><br> <input type="radio" name="method" value="radio" <?php echo $method=='case'?'checked':'' ?>> <input type="radio" name="conversion" value="upper" <?php echo $conversion=='upper'?'checked':'' ?>> 大文字に <input type="radio" name="conversion" value="lower" <?php echo $conversion=='lower'?'checked':'' ?>> 小文字に <input type="radio" name="conversion" value="invert" <?php echo $conversion=='invert'?'checked':'' ?>> 逆に <input type="radio" name="conversion" value="random" <?php echo $conversion=='random'?'checked':'' ?>> ランダムに </td></tr> <tr><td colspan="3"><textarea name="text" rows="20" cols="60"><?php echo $text ?></textarea></td></tr> </table> <input type="button" value="置換する" onClick="var replacer = new Replacer(this.form.nocase.checked, this.form.regexp.checked, getRadio(this.form.method), getRadio(this.form.conversion)); this.form.text.value = replacer.replaceText(this.form.find.value, this.form.replace.value, this.form.text.value); return false;"> </form> <br><br> <?php ?>
'globals-ja.js'のソースコードは以下に示す。
<!-- hide script from old browsers /** * @fileoverview * 共通な作業を行うグローバルなクラスを含んでいる. * * <pre> * globals.js * Copyright (C) 2006-2007, Bowo Prasetyo * * http://www.my-tool.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation below, * * http://www.gnu.org/licenses/gpl.html * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * このプログラムはフリーソフトウェアです。あなたはこれを、以下のURLにフリーソフトウェ * ア財団によって発行された GNU 一般公衆利用許諾契約書の定める条件の下で * 再頒布または改変することができます。 * * http://www.gnu.org/licenses/gpl.html * * このプログラムは有用であることを願って頒布されますが、*全くの無保証* * です。商業可能性の保証や特定の目的への適合性は、言外に示されたものも含 * め全く存在しません。詳しくはGNU 一般公衆利用許諾契約書をご覧ください。 * * あなたはこのプログラムと共に、GNU 一般公衆利用許諾契約書の複製物を一部 * 受け取ったはずです。もし受け取っていなければ、フリーソフトウェア財団ま * で請求してください(宛先は the Free Software Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA)。 * </pre> */ /** * ラジオボタンの選択した値を取得する * * @param {Array} obj ラジオボタン(<input type="radio">)オブジェクト * @return ラジオボタンの選択した値 * @type String */ function getRadio(obj) { for (var i=0; i < obj.length; i++) { if (obj[i].checked) return obj[i].value; } } /** * 複数行の選択タグ<select>の選択した値を配列として取得する * * @param {Object} ob Selectオブジェクト * @return 選択した値の配列 * @type Array */ function getMultiple(ob) { var arSelected = new Array(); for (var i = 0; i < ob.options.length; i++) if (ob.options[i].selected) arSelected[arSelected.length] = ob.options[i].value; return arSelected; } /** * 正規表現の文字列中のメタ文字をエスケープする * * @param {String} str エスケープする正規表現の文字列 * @return エスケープした普通の文字列 * @type String */ function unregexp(str) { return str.replace(/([\\|()[\]{}^$*+?.])/g, "\\$1"); } /** * 文字列の左側と右側から空白文字を切り捨てる */ String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } /** * 文字列の複数並んだ空白文字を一つに圧縮する */ String.prototype.compress = function() { return this.replace(/\s+/g, ' '); } // end hiding script from old browsers -->
'replacer-ja.js'のソースコードは以下に示す。
<!-- hide script from old browsers /** * @fileoverview * Contains a class to replace strings in a text. * * <pre> * replacer.js, Replaces word by another word or just modify its case. Also supports regular expression. * Copyright (C) 2006, Bowo Prasetyo * * http://www.my-tool.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation below, * * http://www.gnu.org/licenses/gpl.html * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * このプログラムはフリーソフトウェアです。あなたはこれを、以下のURLにフリーソフトウェ * ア財団によって発行された GNU 一般公衆利用許諾契約書の定める条件の下で * 再頒布または改変することができます。 * * http://www.gnu.org/licenses/gpl.html * * このプログラムは有用であることを願って頒布されますが、*全くの無保証* * です。商業可能性の保証や特定の目的への適合性は、言外に示されたものも含 * め全く存在しません。詳しくはGNU 一般公衆利用許諾契約書をご覧ください。 * * あなたはこのプログラムと共に、GNU 一般公衆利用許諾契約書の複製物を一部 * 受け取ったはずです。もし受け取っていなければ、フリーソフトウェア財団ま * で請求してください(宛先は the Free Software Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA)。 * </pre> */ /** * Replacerオブジェクトを生成する * * @class * テキスト中の文字列を置換する。 * * テキスト中の文字列は他の文字列に置換するかただ単にケースを変換するか。 * <br><br> * 使用例: * <code><pre> * var replacer = new Replacer(false, true, 'case', 'random'); * document.write(replacer.replaceText('[aiueo]', '', 'All vowels in this text will be converted to random case.'));</pre></code> * * 以上の例はつぎの結果を出力する: * <br><br> * All vowEls in this tExt wIll bE convertEd tO rAndOm cAsE. * <br> * @constructor * @param {bool} nocase 大・小文字の区別を無視するかどうか * @param {bool} regexp 正規表現を使用するかどうか * @param {String} method 置換方法 * @param {String} conversion ケース変換方法 * @author Bowo Prasetyo <praNzjOp@SgmaPilA.cMom> (take N O S P A M for email) */ function Replacer(nocase, regexp, method, conversion) { /** * 大・小文字の区別を無視するかどうか * @type bool */ this.nocase = nocase; /** * 正規表現を使用するかどうか * @type bool */ this.regexp = regexp; /** * 置換方法。 * * 可能な値は: * <ul><li>'text': 置換として文字列(<input type="text">)を用いる * <li>'case': 置換としてケース変換(<input type="radio">)を用いる</ul> * @type String */ this.method = method; /** * ケース変換方法。 * * 可能な値は: * <ul><li>'upper': 大文字に変換する * <li>'lower': 小文字に変換する * <li>'invert': ケースを逆にする * <li>'random': ケースをランダムにする</ul> * @type String */ this.conversion = conversion; } /** * 文字列を検索して置換する * * @param {String} find 検索する文字列 * @param {String} replace 置換文字列 * @param {Stirng} text 元のテキスト * @return すべての「find」が「replace」に置換したテキスト * @type String */ Replacer.prototype.replaceText = function(find, replace, text) { var result, i; if (this.nocase && this.regexp) { if (this.method=='text') result = text.replace(new RegExp(find, 'ig'), replace); else { if (this.conversion=='upper') result = text.replace(new RegExp(find, 'ig'), function($0){ return $0.toUpperCase(); }); else if (this.conversion=='lower') result = text.replace(new RegExp(find, 'ig'), function($0){ return $0.toLowerCase(); }); else if (this.conversion=='invert') result = text.replace(new RegExp(find, 'ig'), function($0){ var str = $0; return str.replace(/([a-z])|([A-Z])/g, function($0,$1,$2){ return ($1)?$0.toUpperCase():$0.toLowerCase(); }); }); else result = text.replace(new RegExp(find, 'ig'), function($0){ var str = $0; return str.replace(/([a-z])|([A-Z])/g, function($0,$1,$2){ return Math.random()>0.5?(($1)?$0.toUpperCase():$0.toLowerCase()):$0; }); }); } } else if (this.regexp) { if (this.method=='text') result = text.replace(new RegExp(find, 'g'), replace); else { if (this.conversion=='upper') result = text.replace(new RegExp(find, 'g'), function($0){ return $0.toUpperCase(); }); else if (this.conversion=='lower') result = text.replace(new RegExp(find, 'g'), function($0){ return $0.toLowerCase(); }); else if (this.conversion=='invert') result = text.replace(new RegExp(find, 'g'), function($0){ var str = $0; return str.replace(/([a-z])|([A-Z])/g, function($0,$1,$2){ return ($1)?$0.toUpperCase():$0.toLowerCase(); }); }); else result = text.replace(new RegExp(find, 'g'), function($0){ var str = $0; return str.replace(/([a-z])|([A-Z])/g, function($0,$1,$2){ return Math.random()>0.5?(($1)?$0.toUpperCase():$0.toLowerCase()):$0; }); }); } } else if (this.nocase) { if (this.method=='text') result = text.replace(new RegExp(unregexp(find), 'ig'), replace); else { if (this.conversion=='upper') result = text.replace(new RegExp(unregexp(find), 'ig'), function($0){ return $0.toUpperCase(); }); else if (this.conversion=='lower') result = text.replace(new RegExp(unregexp(find), 'ig'), function($0){ return $0.toLowerCase(); }); else if (this.conversion=='invert') result = text.replace(new RegExp(unregexp(find), 'ig'), function($0){ var str = $0; return str.replace(/([a-z])|([A-Z])/g, function($0,$1,$2){ return ($1)?$0.toUpperCase():$0.toLowerCase(); }); }); else result = text.replace(new RegExp(unregexp(find), 'ig'), function($0){ var str = $0; return str.replace(/([a-z])|([A-Z])/g, function($0,$1,$2){ return Math.random()>0.5?(($1)?$0.toUpperCase():$0.toLowerCase()):$0; }); }); } } else { if (this.method=='text') result = text.replace(new RegExp(unregexp(find), 'g'), replace); else { if (this.conversion=='upper') result = text.replace(new RegExp(unregexp(find), 'g'), function($0){ return $0.toUpperCase(); }); else if (this.conversion=='lower') result = text.replace(new RegExp(unregexp(find), 'g'), function($0){ return $0.toLowerCase(); }); else if (this.conversion=='invert') result = text.replace(new RegExp(unregexp(find), 'g'), function($0){ var str = $0; return str.replace(/([a-z])|([A-Z])/g, function($0,$1,$2){ return ($1)?$0.toUpperCase():$0.toLowerCase(); }); }); else result = text.replace(new RegExp(unregexp(find), 'g'), function($0){ var str = $0; return str.replace(/([a-z])|([A-Z])/g, function($0,$1,$2){ return Math.random()>0.5?(($1)?$0.toUpperCase():$0.toLowerCase()):$0; }); }); } } return result; } // end hiding script from old browsers -->
©2006 my-Tool.com