私は答えが私を見つめていることを賭けているので、私は愚かにこれを尋ねる気がするが、ここに行く。テスト時にregexオブジェクトで作業を置き換えないのはなぜですか?
私はCSSスタイルのtextDecorationから文字列を取り込み、その文字列の下線部分(およびその周りの空白部分)を削除しようとしています。私はtest()を実行するとtrueを返しますが、replaceメソッドを実行すると文字列は変更されません。助けて?
マイコード:
textDecoration = function(str) {
var n_str = str + '|/\s' + str + '|/\s' + str + '/\s|' + str + '/\s';
var nre = new RegExp(n_str, "g");
debug_log('Found or not: ' + nre.test(txt));
txt.replace(nre, '');
debug_log('Result: ' + txt);
debug_log('-----------------------');
}
var txt = "underline";
debug_log('-----------------------');
debug_log('Starting String: ' + txt);
textDecoration("underline");
txt = "underline overline line-through";
debug_log('-----------------------');
debug_log('Starting String: ' + txt);
textDecoration("underline");
txt = "overline underline line-through";
debug_log('-----------------------');
debug_log('Starting String: ' + txt);
textDecoration("underline");
txt = "overline line-through underline";
debug_log('-----------------------');
debug_log('Starting String: ' + txt);
textDecoration("underline");
出力:
私は恥ずかしいです...ありがとう。私はT-Minusで8分間受け入れます。 –