tags:

views:

52

answers:

1

I'd like to capitalize the first letter following a colon or an ? in javascript.

Ex. Coregulation: an integrative analysis --> Coregulation: An integrative analysis

Or: Coregulation? an integrative analysis --> Coregulation? An integrative analysis

I'd like to make the replacement during the body onload, which I already use to make some other replacements. Ex.

function myscript() {

document.body.innerHTML = document.body.innerHTML.replace(/\.\s\,/g,\"\.\,\"); document.body.innerHTML = document.body.innerHTML.replace(/\s\./g,\"\.\"); document.body.innerHTML = document.body.innerHTML.replace(/\.\(/g,\"\. \(\");

}

Does anybody would know how to do this?

Thanks!

A: 
var regex = /([:\?]\s+)(.)/g;

function correctify(full, prefix, letter){
  return prefix + letter.toUpperCase();
}

document.body.innerHTML = document.body.innerHTML.replace(regex, correctify); 
jimbojw
Nice! Great work! Thanks a lot!