title: Concrete JavaScript regular expression for accented characters (diacritics)
body: <p>I've looked on Stack Overflow (<a href="https://stackoverflow.com/questions/286921/efficiently-replace-all-accented-characters-in-a-string">replacing characters.. eh</a>, <a href="https://stackoverflow.com/questions/5436824/matching-accented-characters-with-javascript-regexes#comment22195688_11550799">how JavaScript doesn't follow the Unicode standard concerning RegExp</a>, etc.) and haven't really found a concrete answer to the question &quot;<em>How can JavaScript match accented characters (those with diacritical marks)?</em>&quot;</p>
  <p>I'm forcing a field in a UI to match the format: <code>last_name, first_name</code> <em>(last [comma space] first)</em>, and I want to provide support for diacritics, but evidently in JavaScript it's a bit more difficult than other languages/platforms.</p>
  <p>This was my original version, until I wanted to add diacritic support:</p>
  <p><code>/^[a-zA-Z]+,\s[a-zA-Z]+$/</code></p>
  <p>Currently I'm debating one of three methods to add support, all of which I have tested and work (at least to some extent, I don't really know what the &quot;extent&quot; is of the second approach). Here they are:</p>
  <h2>Explicitly listing all accented characters that I would want to accept as valid (lame and overly-complicated):</h2>
  <hr />
  <pre><code>var accentedCharacters = &quot;àèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖÜŸçÇßØøÅåÆæœ&quot;;
  // Build the full regex
  var regex = &quot;^[a-zA-Z&quot; + accentedCharacters + &quot;]+,\\s[a-zA-Z&quot; + accentedCharacters + &quot;]+$&quot;;
  // Create a RegExp from the string version
  regexCompiled = new RegExp(regex);
  // regexCompiled = /^[a-zA-ZàèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖÜŸçÇßØøÅåÆæœ]+,\s[a-zA-ZàèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖÜŸçÇßØøÅåÆæœ]+$/
  </code></pre>
  <ul>
  <li>This correctly matches a last/first name with any of the supported accented characters in <code>accentedCharacters</code>.</li>
  </ul>
  <hr />
  <h2>My other approach was to use the <code>.</code> character class, to have a simpler expression:</h2>
  <pre><code>var regex = /^.+,\s.+$/;
  </code></pre>
  <ul>
  <li>This would match for just about anything, at least in the form of: <code>something, something</code>. That's alright I suppose...</li>
  </ul>
  <hr />
  <h2>The last approach, which I just <a href="https://stackoverflow.com/questions/5436824/matching-accented-characters-with-javascript-regexes#comment22195688_11550799">found</a> might be simpler...</h2>
  <pre><code>/^[a-zA-Z\u00C0-\u017F]+,\s[a-zA-Z\u00C0-\u017F]+$/
  </code></pre>
  <ul>
  <li>It matches a range of Unicode characters - tested and working, though I didn't try anything crazy, just the normal stuff I see in our language department for faculty member names.</li>
  </ul>
  <hr />
  <p>Here are my concerns:</p>
  <ol>
  <li><p>The first solution is far too limiting, and sloppy and convoluted at that. It would need to be changed if I forgot a character or two, and that's just not very practical.</p>
  </li>
  <li><p>The second solution is better, concise, but it probably matches far more than it actually should. I couldn't find any real documentation on <em>exactly</em> what <code>.</code> matches, just the generalization of &quot;any character except the newline character&quot; (from a table on the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_Special_Characters" rel="noreferrer">MDN</a>).</p>
  </li>
  <li><p>The third solution seems the be the most precise, but are there any gotchas? I'm not very familiar with Unicode, at least in practice, but looking at a <a href="http://www.utf8-chartable.de/" rel="noreferrer">code table</a>/<a href="http://www.utf8-chartable.de/unicode-utf8-table.pl?start=256" rel="noreferrer">continuation of that table</a>, <code>\u00C0-\u017F</code> seems to be pretty solid, at least for my expected input.</p>
  </li>
  </ol>
  <ul>
  <li>Faculty won't be submitting forms with their names in their native language (e.g., Arabic, Chinese, Japanese, etc.), so I don't have to worry about out-of-Latin-character-set characters</li>
  </ul>
  <hr />
  <p>Which of these three approaches is most suited for the task? Or are there better solutions?</p>