{"ScriptPreparationCode":"function replaceAll(str, regexp, newValue) {\r\n let newStr = str;\r\n\r\n while (regexp.test(newStr)) {\r\n newStr = newStr.replace(regexp, newValue);\r\n }\r\n\r\n return newStr;\r\n}\r\n\r\nfunction replaceAllCountMatches(str, regexp, newValue) {\r\n let newStr = str;\r\n \r\n for (let i = 0; i \u003C matchesCounter; i\u002B\u002B) {\r\n newStr = newStr.replace(regexp, newValue);\r\n }\r\n\r\n return newStr;\r\n}\r\n\r\nvar str = \u0027Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis a\u0027;\r\nvar matchesCounter = (str.match(/\\s\u002B/g) || []).length;\r\nvar result;","TestCases":[{"Name":"replace","Code":"result = str.replace(/\\s\u002B/g, \u0027\u0027);","IsDeferred":false},{"Name":"replaceAll","Code":"result = str.replaceAll(/\\s\u002B/g, \u0027\u0027);","IsDeferred":false},{"Name":"replace in a loop without g flag","Code":"result = replaceAll(str, /\\s\u002B/, \u0027\u0027);","IsDeferred":false},{"Name":"replace in a loop, count matches with g flag, replace without g flag","Code":"result = replaceAllCountMatches(str, /\\s\u002B/, \u0027\u0027);","IsDeferred":false}]}