[Javascript] .match() method

Clancy Jones clancyjones at hotmail.com
Mon Aug 2 19:36:16 CDT 2004


Hi, I haven't used the match() method before but am trying to use it in 
conjunction with the length property to find out how many instances of a 
substring are contained within a string.

I grabbed this example from my Google search:

<script language="JavaScript">
var s = "Tony was here. Not Bob, Tony's brother, but Tony himself.";
var occur = s.match("Tony");
document.write(occur.length);
</script>

The site listing the above said the output should be 3 but I get 1.  I am 
using IE6.

Can someone point me in the right direction?

Thanks a lot,
Clancy

_________________________________________________________________
Surf the net and talk on the phone with Xtra JetStream @  
http://xtra.co.nz/jetstream




More information about the Javascript mailing list