{"ScriptPreparationCode":"var a = \u0027abcdefghijklmnopqrstuvwxyz\u0027;\r\nvar b = \u0027NOP\u0027;\r\n\r\nvar locale = \u0027en-US\u0027\r\n\r\n/////////////////////////////////////////////////////////////////////////////////////\r\n\r\nvar BACKSLASH = \u0027\\\\\u0027;\r\nvar escapeMap = new Map(\r\n [\r\n \u0027\\\\\u0027,\r\n \u0027^\u0027,\r\n \u0027$\u0027,\r\n \u0027*\u0027,\r\n \u0027\u002B\u0027,\r\n \u0027?\u0027,\r\n \u0027(\u0027,\r\n \u0027)\u0027,\r\n \u0027[\u0027,\r\n \u0027]\u0027,\r\n \u0027{\u0027,\r\n \u0027}\u0027,\r\n \u0027=\u0027,\r\n \u0027:\u0027,\r\n \u0027!\u0027,\r\n \u0027|\u0027,\r\n ].map(char =\u003E [char, \u0060${BACKSLASH}${char}\u0060])\r\n);\r\n\r\nvar escapeRegExp = (searchPhrase) =\u003E\r\n [...searchPhrase]\r\n .map(character =\u003E escapeMap.get(character) || character)\r\n .join(\u0027\u0027);\r\n\r\nvar findMatchGroupsOld = (\r\n searchPhrase,\r\n valueToSearchOn\r\n) =\u003E {\r\n const safeSearchPhrase = escapeRegExp(searchPhrase);\r\n const searchPhraseRegExp = new RegExp(\u0060(.\u002B)?(${safeSearchPhrase})(.\u002B)?\u0060, \u0027i\u0027);\r\n const match = valueToSearchOn.match(searchPhraseRegExp);\r\n if (match) {\r\n const [, preFind = \u0027\u0027, find = \u0027\u0027, postFind = \u0027\u0027] = match;\r\n return [preFind, find, postFind];\r\n }\r\n return [valueToSearchOn, \u0027\u0027, \u0027\u0027];\r\n};\r\n\r\n/////////////////////////////////////////////////////////////////////////////////////\r\n\r\nvar localeIndexOfLowercase = (value, searchPhrase, locale) =\u003E {\r\n const searchPhraseLowercase = searchPhrase.toLocaleLowerCase(locale);\r\n\r\n return value.toLocaleLowerCase(locale).indexOf(searchPhraseLowercase);\r\n};\r\n\r\nvar findMatchGroupsNew = (value, searchPhrase, locale) =\u003E {\r\n const index = localeIndexOfLowercase(value, searchPhrase, locale);\r\n const lastIndex = index \u002B searchPhrase.length;\r\n\r\n if (index === -1) return { preMatch: value, match: \u0027\u0027, postMatch: \u0027\u0027 };\r\n\r\n return {\r\n preMatch: value.slice(0, index),\r\n match: value.slice(index, lastIndex),\r\n postMatch: value.slice(lastIndex),\r\n };\r\n};\r\n\r\n\r\n","TestCases":[{"Name":"findMatchGroupsOld","Code":"findMatchGroupsOld(b, a)","IsDeferred":false},{"Name":"findMatchGroupsNew","Code":"findMatchGroupsNew(a, b)","IsDeferred":false}]}