Is it possible to search and replace text without touching html tags?

  • Hi
    I was wondering if we can search and replace text in a HTML file but not in the HTML tags only the text that appear when you load an HTML page in a browser?

    For example, say I want to replace the letter A by B in this line :

    <A HREF=“url”>A B C </A>

    Since the letter A is also in the tags, is it possible to only replace the letter A appearing outside the tags?

    Thank you much for your help guys

  • Hello, @alfredodo1 and All

    The regex S/R, below, would search for any A letter, whatever its case, inside the dots area ( . ) ONLY, even if divided in several lines, in the statement <A HREF=bla bla bla bla blah>..................</A> and replace it with the uppercase letter B

    SEARCH (?si)(?:\G|<A HREF=.+?>)(?:(?!<|>).)*?\KA


    Notes :

    • The part, to look for, is located after the \K

    • Of course you may use other tags , instead of “a href=” !

    Just test it with that text below :

     <A HREF="">Visit "W3Schools" to get the 'A B C' of HTML, JAVASCRIPT, PHP, XML, ASP,... !</A>
     <a href="">Visit "W3Schools" to get the 'a b c' of HTML, JAVASCRIPT, PHP, XML, ASP,... !</a>
     <A href="">
     Visit "W3Schools" to get 
     the 'A B C' of html, javascript, php
     , xml, asp,... !

    Best Regards,


  • Hi guy038 you really rock thank you so much for your help, that’s very kind from you. Your solution works wonder, thanks for this very detailed help !

Log in to reply