2
是否可以將找到的單詞插入到替換中?Javascript正則表達式 - 插入單詞(點擊)
$(function() {
content = 'hallo mein name ist peter und ich komme aus berlin. Und du?';
words = 'mein na,berlin'
words = words.replace(/,/,'\|');
words = words.replace(/\s/,'\\s');
regex = new RegExp(words,'gi');
content = content.replace(regex,'<strong>*insert here the word that was found*</strong>');
alert(''+content+'');
});
工作示例 http://www.jsfiddle.net/V9Euk/227/
提前感謝! 彼得
非常感謝您! – Peter 2010-08-26 09:57:59
@Peter - 沒問題。祝你好運! – Kobi 2010-08-26 10:07:42