title: RegEx for JavaScript variables with nested names
body: <p>When I needed to match a simple open-value JavaScript variable, I used the following RegEx:</p>
  
  <pre><code>\s*[a-zA-Z0-9$_]+\s*
  </code></pre>
  
  <p>Now I need to add support for nested properties, i.e. there can be dots (<code>.</code>) in the name, with the following considerations:</p>
  
  <ul>
  <li><code>.</code> cannot be in the beginning or end</li>
  <li>a single <code>.</code> on its own is not valid</li>
  <li>repeated dots (<code>a..b</code>) are not allowed</li>
  </ul>
  
  <p>What would be the right/simplest way to amend such a RegEx pattern?</p>
  
  <p>If it makes any difference, I'm only interested in a version that will work under Node.js</p>
  
  <hr>
  
  <p><strong>Valid Examples</strong></p>
  
  <ul>
  <li><code>a</code></li>
  <li><code>a.b</code></li>
  <li><code>a.b.c</code></li>
  <li><code>_.$.123</code></li>
  </ul>
  
  <p><strong>Invalid Examples</strong></p>
  
  <ul>
  <li>``</li>
  <li><code>.</code></li>
  <li><code>.a</code></li>
  <li><code>a.</code></li>
  <li><code>a..b</code></li>
  </ul>