Edit in JSFiddle

 if (/[A-Z]/.test(before[0])) {
   after = after[0].toUpperCase() + after.substring(1, after.length);
 }