How to dinamically change the string in a find statement?

  • Thread starter Yves-Alain NICOLLET
  • Start date
Y

Yves-Alain NICOLLET

I have a script that opens a small window containing a button which
when clicked performs a find to the next occurence of a string. It
works well when the string is made of only one word or of consecutive
words.
Now I want it to find the next occurence of one of the words contained
in a list, ie. I want to dynamically change the string to find.
I failed to use a regular expression instead of a string in the find
statement.
Any idea of how I can do that?
Thanks.
 
Y

Yves-Alain NICOLLET

I have a script that opens a small window containing a button which
when clicked performs a find to the next occurence of a string. It
works well when the string is made of only one word or of consecutive
words.
Now I want it to find the next occurence of one of the words contained
in a list, ie. I want to dynamically change the string to find.
I failed to use a regular expression instead of a string in the find
statement.
Any idea of how I can do that?
Thanks.

To make myself clearer, is there a way to say:

find(a_word OR another_word OR yet_another_word OR etc) ?
 
T

Thomas 'PointedEars' Lahn

Yves-Alain NICOLLET said:
(e-mail address removed) (Yves-Alain NICOLLET) wrote in message
news:<[email protected]>...

Please do not write attribution novels.

Note the security restrictions for the window size:

http://devedge.netscape.com/manuals/2000/javascript/1.3/reference/window.html#1202731>
[...] Now I want it to find the next occurence of one of
the words contained in a list, ie. I want to dynamically change the
string to find. I failed to use a regular expression instead of a
string in the find statement. Any idea of how I can do that? Thanks.

To make myself clearer, is there a way to say:

find(a_word OR another_word OR yet_another_word OR etc) ?

Depends. There is the proprietary window.find() method which
returns `true' if unsuccessful, `false' otherwise. So you can
do consecutive searches:

function findWords()
{
var t;
if ((t = typeof window.find) == "function"
|| (t == object && window.find != null))
{
for (var i = 0, len = arguments.length; i < len; i++)
{
var s = arguments;
if (window.find(s))
{
return true; // or s if you like
}
}
}

return false; // no match
}

if (!findWords("a_word", "another_word", "yet_another_word", "etc"))
{
alert("No match for either"
+ "'a_word', 'another_word', 'yet_another_word' or 'etc'");
}

If you want two or more words to be matched and to be selected at
the same time, you need to parse the documents content. Dirty
proprietary quickhack:

document.body.innerHTML.replace(
/(a_word|another_word|yet_another_word|etc)/g,
'<span style="background-color:yellow; color:black">$1</span>');


HTH

PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
[...] There is the proprietary window.find() method which
returns `true' if unsuccessful, `false' otherwise. [...]

returns `true' if successful, `false' otherwise. [...]


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
If you want two or more words to be matched and to be selected at
the same time, you need to parse the documents content. Dirty
proprietary quickhack:

document.body.innerHTML.replace(
/(a_word|another_word|yet_another_word|etc)/g,
'<span style="background-color:yellow; color:black">$1</span>');

This changes nothing really and "must be" "of course"[1]

document.body.innerHTML = document.body.innerHTML.replace(
/(a_word|another_word|yet_another_word|etc)/g,
'<span style="background-color:yellow; color:black">$1</span>');


PointedEars
___________
[1] Note it is still an evil quickhack.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top