RegEx Escaped String Test

Test to see which regular expressions can properly match a giant string while respecting any escapes.

HTML

<button onclick='test( /\"(\\.|[^\"])*\"/gi )'>Test A</button>
<button onclick='test( /"(?:[^"\\]|\\.)*"/gi )'>Test B</button>
<button onclick='test( /"(([^"\\]?(\\\\)?)|(\\")+)+"/gi )'>Test C</button>
<button onclick='test( /"([^"\\]*(\\.[^"\\]*)*)"/gi )'>Test D</button>
<br/><br/>
Results: <div id="output">(none)</div>

CSS

* { font-family: sans-serif; font-size: 10pt; }

JavaScript

// A test to see which regular expressions can properly handle a large (1.5KB) string with around 100 escapes

// All cases except D result in a stack overflow error in BBEdit and TextWrangler for Mac. They may also cause the same in other software that uses grep. Though A, B, and D all seem to work in the browser (Firefox 36)

// See also http://stackoverflow.com/questions/249791/

window.$ = function( id ){ return document.getElementById( id ); };

window.test = function( r ){ $( 'output' ).innerHTML = testString.match( r ).join(', '); }

var testString = ' "Foo \\"Bar\\"" Gaz...