Hi All,
Does anybody know if there's a way to find out how many words
appear in a string using regular expression in javascript? For
example, I have the following code that pops a "Not OK" alert
whenever str contains "it it it information technology", and I need
to find out how many times the word "it" exists in the string using
regular expression.
<html>
<body>
<script type="text/javascript">
var str = "it it it information technology";
var reg = /^(\bin\b|\bit\b|\bof\b)(?!
(\bin\b|\bit\b|\bof\b))/;
reg = new RegExp(reg);
var result = str.match(reg);
document.write(result);
if (result) {
alert("OK");
} else {
alert("Not OK");
}
</script>
</body>
</html>
Thanks very much in advance!