I am doing an iframe upload of a file I parse and when I look at the .innerHTML
of the iframe, my response is in pre
tags. I just want to get the data without the pre
tags. I figured since it's a one-off thing we are doing here, and we validate the data server-side, I know that my data will just have the opening and closing pre
tags.
On this regex tester: http://www.regular-expressions.info/javascriptexample.html,
I use this regex:
<pre>(.*?)</pre>
On my test data:
<pre>{test : foo}</pre>
On this site, when I ask it to "Show Match", it gives me back
{test:foo}
But when I try this in my actual code, I do:
var iframeContents = $("#postiframe").get(0).contentWindow.document.body.innerHTML;
var re = new RegExp("<pre>(.*?)</pre>");
var results = iframeContents.match(re);
console.log(iframeContents);
console.log("results");
console.log(results);
Note: I had to use the new RegExp
style since I couldn't figure out how in Typescript to create a literal regex. In any case, when I log the results,
results[0]
looks like:
<pre>{test : foo}</pre>
results[1]
looks like:
{test:foo}
Is that correct to get two matches like that?