开发者

Capitalize first letter following colon and ?: Javascript

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

Ex. Coregulation: an int开发者_开发知识库egrative 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!


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

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

document.body.innerHTML = document.body.innerHTML.replace(regex, correctify); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜