给replace()传递一个函数

var sFlop = "Flop: [Ah] [Ks] [7c]"; var aValues = {"A":"Ace","K":"King",7:"Seven"}; var aSuits = {"h":"Hearts","s":"Spades", "d":"Diamonds","c":"Clubs"}; sFlop = sFlop.replace(//[/w+/]/gi, function(match) {   match = match.replace(match[2], aSuits[match[2]]);   match = match.replace(match[1], aValues[match[1]] +" of ");   return match; }); // string sFlop now contains: // "Flop: [Ace of Hearts] [King of Spades] [Seven of Clubs]" 

你可能感兴趣的:(javascript)