我在 Jquery 中有这段代码-:
message = '#Usain Bolt #Usain Bolt #Usain Bolt'; message = " "+message+" ";
var type1 = 'Usain Bolt';
if(message.match(type1))
{
var matchOne = new RegExp(' #'+type1+' ', 'g');
var matchTwo = new RegExp('\n#'+type1+' ', 'g');
message = message.replace(matchOne," @"+type1+" ").replace(matchTwo,"\n@"+type1+" ");
}
结果消息应该是@Usain Bolt @Usain Bolt @Usain Bolt
但是它变成了-:@Usain Bolt #Usain Bolt @Usain Bolt
有什么问题。感谢帮助..