title: Rstrip based on regex in Javascript
body: <p>I'm trying to validate a list of email addresses client-side. These addresses are separated by a comma or a semi-colon. They typically look like this:</p>
  
  <pre><code>'fake@mail.com; another@mail.com; '
  'myaddress@mail.com, myfriend@mail.com'
  </code></pre>
  
  <p>I'm using a regular expression to split the string (I know how to validate each email address separately):</p>
  
  <pre><code>var separator = /[;,]+/;
  var emails = value.split(separator);
  </code></pre>
  
  <p>I want to be able to remove the last separator if there is one. Server-side in python I'm doing something like that:</p>
  
  <pre><code>data = data.rstrip(separator)
  value_list = re.split(separator, data)
  </code></pre>
  
  <p>With separator being the desired regexp.</p>
  
  <p>My question is: how do I do this in Javascript ? More broadly, how do I remove the last characters of a string if they match a regexp ?</p>