title: Conditional Renderings with JavaScript Regex
body: <p>I need to match on a string such as this:</p>
  
  <p><code>'if Country equals "United States" then Show'</code></p>
  
  <p>I'm working with the Webforms for Marketers Module in Sitecore.  Sitecore is a .NET based CMS.  The Webforms for Marketers Modules is a module that provides a GUI for non-developers to design forms with textboxes, drop-down lists, checkboxes, etc...  I have requirements to only show certain fields on the form if the user picked a certain option in a previous field.  For example: only show the States drop-down list if the user picked "United States" from the Country drop-down list.  The problem is, the WFFM module doesn't support conditional renderings of fields so I'm trying to implement it myself with JavaScript.  My idea is this:</p>
  
  <ul>
  <li>I'll build out the form in the module with all of the possible fields</li>
  <li>When the page loads, I'll use JavaScript to hide fields that depend on the value of previous fields</li>
  <li>When a user interacts with a field, I'll run some JavaScript to check the value of the field and determine whether or not I should show one or more of the fields that I hid on page load.</li>
  </ul>
  
  <p>I'm basically writing an interpreter for an <code>if</code> statement; I'm giving the marketers a way to "program" the form.  <code>Country</code> is the name of a drop-down list on my page.  <code>equals</code> is a condition.  <code>"United States"</code> is one of the values in drop-down list.  If the user picks <code>United States</code> in the drop-down, <code>then</code> <code>Show</code> the States drop-down list.</p>
  
  <p>So the input for the regex test would always follow this format:</p>
  
  <ul>
  <li>always starts with the keyword <code>if</code></li>
  <li>followed by 1 or more white-spaces</li>
  <li>followed by any number of digits, and/or letters and/or white-spaces
  <ul>
  <li>The name of controls can contain more than one word with spaces and even numbers
  <ul>
  <li>For example: First Name, or, Address Line 1</li>
  </ul></li>
  </ul></li>
  <li>followed by 1 or more white-spaces</li>
  <li>followed by the keyword <code>equals</code></li>
  <li>followed by 1 or more white-spaces</li>
  <li>followed by 1 double-quote</li>
  <li>followed by any number of digits, and/or letters and/or white-spaces
  <ul>
  <li>The value of the control can contain more than one word with spaces and even numbers</li>
  </ul></li>
  <li>followed by 1 double-quote</li>
  <li>followed by 1 or more white-spaces</li>
  <li>followed by the keyword <code>then</code></li>
  <li>followed by either the keyword <code>Show</code> or the keyword <code>Hide</code></li>
  </ul>
  
  <p>I've got this much that works but it's not all of the requirements I've listed above.  This line matches all the way up to the white-space after the control name.</p>
  
  <p><code>var pattern = /^if\s+(\d*|\w*)\s+.*$/;</code></p>
  
  <p>But when I try to match on the double-quote it doesn't work; I don't really know the syntax for matching on the double-quote.  I've tried all of the following, none work:</p>
  
  <p><code>var pattern = /^if\s+(\d*|\w*)\s+["].*$/;</code></p>
  
  <p><code>var pattern = /^if\s+(\d*|\w*)\s+\".*$/;</code></p>
  
  <p><code>var pattern = /^if\s+(\d*|\w*)\s+\"{1}.*$/;</code></p>
  
  <p>Any help you can provide will be greatly appreciated!</p>