const regex = /^var (.*?Infos) = .*?data: (.*?),$/gms;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^var (.*?Infos) = .*?data: (.*?),$', 'gms')
const str = `var syntheticResponseTimeDistributionInfos = {
data: {"result": {"minY": 1.0, "minX": 0.0, "ticks": [[0, "Requests having \\nresponse time <= 500ms"], [1, "Requests having \\nresponse time > 500ms and <= 1,500ms"], [2, "Requests having \\nresponse time > 1,500ms"], [3, "Requests in error"]], "maxY": 37.0, "series": [{"data": [[0.0, 37.0]], "color": "#9ACD32", "isOverall": false, "label": "Requests having \\nresponse time <= 500ms", "isController": false}, {"data": [], "color": "yellow", "isOverall": false, "label": "Requests having \\nresponse time > 500ms and <= 1,500ms", "isController": false}, {"data": [], "color": "orange", "isOverall": false, "label": "Requests having \\nresponse time > 1,500ms", "isController": false}, {"data": [[3.0, 1.0]], "color": "#FF6347", "isOverall": false, "label": "Requests in error", "isController": false}], "supportsControllersDiscrimination": false, "maxX": 3.0, "title": "Synthetic Response Times Distribution"}},
getOptions: function() {
return {
var activeThreadsOverTimeInfos = {
data: {"result": {"minY": 1.0, "minX": 1.5931058172E12, "maxY": 1.0, "series": [{"data": [[1.5931058186E12, 1.0], [1.5931058196E12, 1.0], [1.5931058175E12, 1.0], [1.5931058185E12, 1.0], [1.5931058195E12, 1.0], [1.5931058205E12, 1.0], [1.5931058184E12, 1.0], [1.5931058194E12, 1.0], [1.5931058204E12, 1.0], [1.5931058173E12, 1.0], [1.5931058183E12, 1.0], [1.5931058193E12, 1.0], [1.5931058203E12, 1.0], [1.5931058172E12, 1.0], [1.5931058213E12, 1.0], [1.5931058192E12, 1.0], [1.5931058202E12, 1.0], [1.5931058212E12, 1.0], [1.5931058181E12, 1.0], [1.5931058191E12, 1.0], [1.5931058201E12, 1.0], [1.5931058211E12, 1.0], [1.593105818E12, 1.0], [1.593105819E12, 1.0], [1.59310582E12, 1.0], [1.593105821E12, 1.0], [1.5931058179E12, 1.0], [1.5931058189E12, 1.0], [1.5931058209E12, 1.0], [1.5931058178E12, 1.0], [1.5931058198E12, 1.0], [1.5931058208E12, 1.0], [1.5931058177E12, 1.0], [1.5931058187E12, 1.0], [1.5931058197E12, 1.0], [1.5931058207E12, 1.0], [1.5931058176E12, 1.0]], "isOverall": false, "label": "ThreadGroup", "isController": false}, {"data": [[1.5931058224E12, 1.0], [1.5931058217E12, 1.0]], "isOverall": false, "label": "tearDown Thread Group", "isController": false}], "supportsControllersDiscrimination": false, "granularity": 100, "maxX": 1.5931058224E12, "title": "Active Threads Over Time"}},
getOptions: function() {
`;
const subst = `var $1 = {\n data: $1_data,`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions