Hello
it doesn't matter whether you want to replace or search: what you basically
need is to compile a regular expression on the run, ISN'T IT?
Try the code I sent to you:
<script><!--
var test_string="hallo guy hallo! I said hallo!";
var yourRegExp_as_text="\\w{5}"; //that checks for 5 letters long words
var regExpObject=new RegExp();
//now use the built in method compile
regExpObject.compile(yourRegExp_as_text, "gi");
/*the second argument takes in the so called modifiers. g stands fopr GLOBAL
scope (search ALL the occurrencies, that is), i stands for case INsensitive
search*/
//Now you have a valid regular expression
/*use it with methods that are regular expression methods, instance
replace():*/
test_string=test_string.replace(regExpObject, "HI"); /*replaced hallo with
HI*/
alert(test_string)
//--></script>
Once you don't need replacing, that's not a problem, you can use search:
test_string.seRCH(regExpObject);
You'd have to work a bit yourself on the codes sent as a reply.
Anyway, to get closer to your needs:
<script><!--
var somestringarray = new Array( "one", "two", "three" );
var somestring = "This is one of my favorite";
var regExpObject=new RegExp();
for( var i = 0; i < somestringarray.length; i++ )
{
regExpObject.compile(somestringarray
, "gi");
if( somestring.match( regExpObject ))
{alert(somestringarray)
break;
}
}
//--></script>
ciao
Alberto
http://www.unitedscripters.com/