title: How do I email a parsed string from a spreadsheet each time a google form is submitted?
body: <p>I have created a google form that requires users to select a name and ID from a list. The format of the name and ID can be either of two:</p>
  
  <pre><code>Smith, John (12345)
  Doe, John (JDO)
  </code></pre>
  
  <p>I would like an email to be automatically sent to an address every time the form is submitted with a subject line that is the ID contained in the bracket only. I have the automatic email being sent and can get the entire string from the cell I want, but I need a function that can parse the string down to just what is contained in the brackets. This is what I have so far, pieced together from help I've found on this forum (thanks to amit@labnol.org).</p>
  
  <pre><code>function Initialize() {
  
    var triggers = ScriptApp.getScriptTriggers();
  
    for(var i in triggers) {
      ScriptApp.deleteTrigger(triggers[i]);
    }
  
    ScriptApp.newTrigger("SendGoogleForm")
    .forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
    .onFormSubmit()
    .create();
    }
  
    function SendGoogleForm(e) 
    {  
    try 
    {  
      // You may also replace this with another email address
      var email = "xxxxxx@gmail.com";
  
      // Optional but change the following variable
      // to have a custom subject for Google Docs emails
  
  
      var s = SpreadsheetApp.getActiveSheet();
      var subject = s.getRange(s.getLastRow(),21).getValue();
      var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];    
      var message = "";    
  
      // Credit to Henrique Abreu for fixing the sort order
  
      for(var i in headers) {
        message += headers[i] + ' :: '+ e.namedValues[headers[i]].toString() + "\n\n"; 
      }
  
      message += "Sheet URL :: " + SpreadsheetApp.getActiveSpreadsheet().getUrl() + "\n";
  
      // This is the MailApp service of Google Apps Script
      // that sends the email. You can also use GmailApp here.
  
      MailApp.sendEmail(email, subject, message); 
  
    } catch (e) {
      Logger.log(e.toString());
    }
  
   }
  </code></pre>
  
  <p>I'm only new to javascript, so any help would be greatly appreciated.</p>
  
  <p>Cheers.</p>