title: Using Javascript Regex in Evaluate JS on object step in Vugen TruClient Protocol
body: <p>While creating a script in Vugen using the TruClient protocol (Firefox), I 
  have an <code>Evaluate JS on object</code> step that finds an object, with the
  following <code>object.innerHTML</code>:</p>
  
  <pre><code>Foo Bar&lt;br /&gt;BAZ
  &lt;br /&gt;
  </code></pre>
  
  <p>I need to extract <code>BAZ</code> from this text to use elsewhere, so I have the
  following code in the JS portion, to extract it using a regex:</p>
  
  <pre><code>var regex = /Foo\s+Bar&lt;br\s+\/&gt;(.*)\s*&lt;br \/&gt;/i;  // Shows as red in the TC JS editor, but no error icon shows, so not sure what the error may be.
  var matches = [];
  var match;
  matches = regex.exec(object.innerHTML);
  match = matches[matches.length - 1];
  window.alert(match);  // For debugging purposes
  </code></pre>
  
  <p>However, when I run the script, this fails with the following error:</p>
  
  <pre><code>** 6: Evaluate JavaScript var regex = /Foo\s+B... alert(match); on Foo Bar
  ** failed - an argument is invalid: 'Code': JavaScript exception
  'TypeError: matches is null' during evaluation
  </code></pre>
  
  <p>I have tested this regex <a href="https://regex101.com/r/dO7gY7/2" rel="nofollow noreferrer">here</a>, and it works
  as expected.</p>
  
  <p>Using the <a href="http://www.webtoolkitonline.com/javascript-tester.html" rel="nofollow noreferrer">webtoolkit online JS tester</a>,
  I've successfully tested the following variant on the code, to ensure that it
  extracts what I need it to:</p>
  
  <pre><code>var data = "Foo Bar&lt;br /&gt;BAZ&lt;br /&gt;";
  var regex = /Foo\s+Bar&lt;br\s+\/&gt;(.*)\s*&lt;br \/&gt;/i;
  var matches = [];
  var match;
  matches = regex.exec(data);
  match = matches[matches.length - 1];
  alert(match);
  </code></pre>
  
  <p>This returns <code>BAZ</code> as expected.</p>
  
  <h1>Edit</h1>
  
  <p>I originally assumed this was a Vugen/TruClient specific issue.  However, after sleeping on it and reading Michael Galos' answer (<a href="https://stackoverflow.com/a/35178848/1843248">below</a>), I realized that it was was a generic Javascript issue, so I added the Javascript tag to this as well. </p>