Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Searching for a term and excluding tags

  •  03-02-2008, 7:40 AM

    Searching for a term and excluding tags

    Hi all,

    New to the regex world and trying to figure out the following task.

    I am writing javascript code that will find a given search term in a web page and replace it with some other text I have predefined.

    I managed to achieve this task but for one problem - I need to exclude the search terms surrounded by anchor tags and script tags.

    So my goal is to be able to search and replace given terms excluding the matches found in certain tags.

    Currently I have:

     function findReplace(searchTerm)

        var re = new RegExp(searchTerm, "gi");

        var newtext = oldText.replace(re,"some new stuff");         

        return newtext;

     I need to find a way to exclude the seacrh term found in the tags I mentioned.

    Any ideas how to do this? 

     

     

     

    Filed under:
View Complete Thread