Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 945 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • alfredodo1A
      alfredodo1
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        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

        REPLACE B

        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="https://www.w3schools.com/html/default.asp">Visit "W3Schools" to get the 'A B C' of HTML, JAVASCRIPT, PHP, XML, ASP,... !</A>
         
         <a href="https://www.w3schools.com/html/default.asp">Visit "W3Schools" to get the 'a b c' of HTML, JAVASCRIPT, PHP, XML, ASP,... !</a>
         
         <A href="https://www.w3schools.com/html/default.asp">
         Visit "W3Schools" to get 
         the 'A B C' of html, javascript, php
         , xml, asp,... !
         </a>
        

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 3
        • alfredodo1A
          alfredodo1
          last edited by

          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 !

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors