Guest paritosh1010 Posted December 23, 2006 Share Posted December 23, 2006 Example 2 - Case-insensitive SearchIn the following example we will perform a case-insensitive search:<script type="text/javascript">var str="Visit W3Schools!"document.write(str.search(/w3schools/i))</script> The output of the code above will be:6here, w3schools inside search argument is a string. what if u want to use a variable there, that has w3schools stored in it?lets say variable name was s/s/i wont work, since it treats the thing as a string(s)i wont work either/(s)/i eitherany suggestions? Link to comment Share on other sites More sharing options...
Webworldx Posted December 23, 2006 Share Posted December 23, 2006 <script type="text/javascript">var what_im_searching_for = "w3schools";var my_search = new RegExp( what_im_searching_for , "i");var str="Visit W3Schools!"document.write(str.search( my_search ))</script> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now