I'm going insane trying to figure out why this RegExp is cutting my string in half. The purpose of the pattern is to replace any "tags" within a "%%string%%" tag.
Expected Result: "%%string%%hello 1 and hello 2.%%%end%%%"
Actual Result: "%%string%% and hello 2.%%%end%%%"
Any ideas?
Code:
var data = '"%%string%%hello %%number%%1%%%end%%% and hello %%number%%2%%%end%%%.%%%end%%%"';
var pattern = /(?:"%%string%%)((.*?)(%%number%%([0-9])%%%end%%%))+/g;
var result = data.replace(pattern,'"%%string%%$2$4');
Actual Result: "%%string%% and hello 2.%%%end%%%"
Any ideas?