SO - 4594074

by Arun P Johny

JavaScript

var regex = new RegExp("t", "gi")
var count = "This is some text".match(regex).length;
alert(count)