Click to See Complete Forum and Search --> : Searching for strings


canobi
05-08-2003, 08:13 AM
Hello everyone!

I'm having a bit of a problem with Reggie Expression (RegExp). I'm trying to write a script that gets the number of occurences of a substring within a string. I defined a RegExp with the substring, and a global flag. Then I used the exec() command, which, I'm told, generates an array containing the substring occurences. What I then did was assign the length of this array to a variable.

Unfortunately, this doesn't give me an accurate result. When I add another substring of the type I'm searching for, it still gives me the same result. I understand using the exec() method doesn't recompile, but returns the initial value. This is no good cause my string is bound to change frequently.

Is there a way I can reset the values and conduct a clean search? Is there a better way of searching for substring occurrences? I would really appreciate any help you can give me.

Thanks.:(