How do I make a Javascript replace search case insensitive?
My original string contains tags which are mostly lowercase.
My function that produces the search substring uses the innerHTML property and as such it automaticaly converts all tags to uppercase. So to do the search and replace correctly I need to find a way to make the replace function case in-sensitive.
If you can show a quick example of the tag using the parameter or method that makes it case insensitive it will help me a bunch.
Thanks again for the help.
Hi,
Try the following:
var pattern = new RegExp(your_variable, 'gi');
var str = str.replace(pattern, 'your replacement');
Yours, Erik.
Works pretty good. Thank You. However I just realized that the innerHTML method is also stripping quotes.
So my main string may have quotes, but the section to base the search on will not have the quotes since they are stripped.
So I need the main HTML string to retain the quotes but have the search substring without quotes still match up. Is this possible with some sort of RegEx magic?
Thanks