Go to: https: //www.cnblogs.com/jasonlam/p/7070604.html
var text = "hungry ~ ~ 23333 hungry, test Yongde."; var Word = "hungry ~" ; var NewWorld = "Amount ~ ~ "; text = text.replace (Word, NewWorld); // only the first alternative a text text.replace = ( new new the RegExp (Word, 'G'), NewWorld); // global replacement
Using the JS the RegExp objects, we took out the single parameter g, while the regular content can be replaced with a variable!