JSFiddle - React, Tailwind, and code Playground
by afk
HTML
<p>
This jsfiddle was created for a <a target="_blank" href="http://stackoverflow.com/a/15645279/7331858">stackoverflow</a>
question regarding a work around for cheerio parsing XML with CDATA
</p>
<p>
Debuggex visualization of regex: <a target="_blank" href="https://www.debuggex.com/r/hsmTo97M9Q8s18RF">link</a>
</p>
<h1>Input</h1>
<pre id="input">Output will show up here</pre>
<h1>Output</h1>
<pre id="output">Output will show up here</pre>
CSS
#input, #output {border: 1px solid black;}
JavaScript
let input = `
<data key="d5">
<![CDATA[some data that contains [brackets], numbers 123, and words ...]]>
</data>
<data key="d6">
<![CDATA[more data and random brackets ] [ ]] [[ , and numbers 456]]>
</data>
`.trim();
let regex = /<!\[CDATA\[([\s\S]*?)\]\]>(?=\s*<)/gi;
let filteredInput = input.replace(regex, "$1");
//show results
document.getElementById("input").innerText = input;
document.getElementById("output").innerText = filteredInput;