[Javascript] .match() method
Peter Brunone
peter at brunone.com
Mon Aug 2 21:20:05 CDT 2004
Clancy,
I've never tried this before, but the documentation at
http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthmatch.asp
says this:
"If the global flag (g) is not set, Element zero of the array contains
the entire match..."
Basically, it looks like when this flag is not set, you only get
the first occurrence. FYI, this method is meant to be used with a
regular expression (or string containing regex pattern and flags) as the
search criterion.
Anyway, you can read up at the link above and see if it helps.
Cheers,
Peter Brunone
-----------------------
Do the impossible.
Go home early.
www.EasyListBox.com
-----------------------
-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Clancy Jones
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
More information about the Javascript
mailing list