JSFiddle - React, Tailwind, and code Playground

by Jussia

JavaScript

const str = "Изменение шаблона {xTemplate:asyncTasksLayoutPF} печатной формы невозможно, так как он используется в задаче на выгрузку документа:{xTemplate:asyncTasksReportDelete}";

var replateValues = {}, regex = /{xTemplate:(\w+)}/gm, m;
var xTemplateNames;
		/* while ((xTemplateNames = regex.exec(str)) !== null) {
		  // This is necessary to avoid infinite loops with zero-width matches
		  if (xTemplateNames.index === regex.lastIndex) {
		    regex.lastIndex++;
		  }
		
		  // The result can be accessed through the `m`-variable.
		console.log('xTemplateNames', xTemplateNames)
		   xTemplateNames.forEach(function(match, groupIndex) {
		    console.log(match);
		  }) 
		} */
 while (xTemplateNames = regex.exec(str) !== null) {
			// This is necessary to avoid infinite loops with zero-width matches
			if (xTemplateNames.index === regex.lastIndex) {
				regex.lastIndex++;
			}

			// The result can be accessed through the `m`-variable.
			xTemplateNames.forEach(function(match, groupIndex) {
				console.log(match);
			})
		}