Darksbane
07-30-2002, 11:25 AM
Here is what I am trying to do:
I have an array of sentences. and I would like the user to be able to enter in a word which is then inserted into a regular expression to find all sentences with that word in it.
Here is an example
SentenceArray= new Array (
"I have a dog",
"dogs are good",
"cats are bad.")
The user then enters in the word "dog"
the regular expression should then look like this I think:
regexp = /dog/
and then an if is set up like
for (...) {
if (regexp.test(SentenceArray[X]){
do something
}
}
I am not exactly sure what I am doing wrong, but I have figured out that it doesn't like "regexp.test(SentenceArray[X])" and only seems to take some kind of form element. I tried a hidden field instead and that got it to stop giving an error, but I still never get any results.
Any help or suggestionw would be appreciated.
I have an array of sentences. and I would like the user to be able to enter in a word which is then inserted into a regular expression to find all sentences with that word in it.
Here is an example
SentenceArray= new Array (
"I have a dog",
"dogs are good",
"cats are bad.")
The user then enters in the word "dog"
the regular expression should then look like this I think:
regexp = /dog/
and then an if is set up like
for (...) {
if (regexp.test(SentenceArray[X]){
do something
}
}
I am not exactly sure what I am doing wrong, but I have figured out that it doesn't like "regexp.test(SentenceArray[X])" and only seems to take some kind of form element. I tried a hidden field instead and that got it to stop giving an error, but I still never get any results.
Any help or suggestionw would be appreciated.