看到这个:
http://jsfiddle.net/2hNwL/1/
但正如奥利指出的那样,这是毫无意义的。考虑到您可能想要替换字符串知识,我也使用了替换功能:
var str = 'Science (from Latin scientia, meaning "knowledge") is a systematic enterprise that builds and organizes knowledge in the form of testable explanations and predictions about the universe.[1] In an older and closely related meaning (found, for example, in Aristotle)';
var match = str.match(/knowledge/gi);
if(match != null)
{
for(var i = 0; i < match.length; i++)
alert(match[i]);
var replacedString = str.replace(/knowledge/gi,'egdelwonk');
alert(replacedString);
}
根据您的编辑,请参阅我的新 jsfiddle:http: //jsfiddle.net/kPRDH/
var str = 'Dear [name] ,This is to inform you that blah blah blah blah. you can contact the undersigned. [tele no] ,[address]';
str = str.replace(/\[name\]/g,'TCM');
str = str.replace(/\[tele no\]/g,'9999999999');
str = str.replace(/\[address\]/g,'221B Bakers Street');
alert(str);