Before you mark this as duplicate, let me assure you that I have gone through, hopefully, all of the questions asked on the subject on stackoverflow, including the following:
How can I invert a regular expression in JavaScript?
negation in regular expression
I am trying to parse a string with syntax as follows:
contents = "Some Random Text1 <@@Matched text 1@@> Some Random Text2 <@@Matched text 2@@> Some Random Text3";
I used the regular express:
reg_exp = /\<\!\!.*?\!\!\>/g
and then used the following code to extract the Matched Text and make a long string out of it with a blank delimiter in between each match.
while ((matched_array = reg_exp.exec(contents)) != null) {
matched_text += (matched_array[0] + "");
};
This returns matched_text as:
<@@Matched text 1@@> <@@Matched text 2@@>
All this works fine. Now I want to get a substring of all text outside the matched text.
I cannot set a regular expression to do the same with the text outside the matched text, to generate the following result string for the above example:
Some Random Text1 Some Random Text2 Some Random Text3
I tried all possible solutions provided in the above cited posts, including (?! or ^ after grouping (), etc.