我正在寻找一种非常简单的方法来获得类似于以下JavaScript代码的等价物。也就是说,对于每个匹配项,我想调用某个转换函数并将结果用作替换值。varres="HelloWorld!".replace(/\S+/,function(word){//Sincethisfunctionrepresentsatransformation,//replacingliteralstrings(aswithreplaceAll)arenotaviablesolution.return""+word.length;})//res=>"56"只有..在Java中。并且,最好作为可以重复使用的“单一方法