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