Community
    • Login

    Need Regex to Delete HTML attribute

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 4 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.
    • Ron Ball 0R
      Ron Ball 0
      last edited by

      I would like to be able to search (and delete) all occurrences of an HTML attribute. for my example, I want to delete the “TITLE” attribute and its value.

      In my text file i have …

      <p>
      <a href="hhhh" title="something">xxx</a>
      <a href="hhhh" title="link #2">xxx</a>
      </p>
      

      Using a RegEx expression, I want to search and find both “TITLE” attributes, (including the equal sign and quote marks) …

      title=“something” AND title=“link #2”

      Please help me!

      Terry RT 1 Reply Last reply Reply Quote 1
      • Terry RT
        Terry R @Ron Ball 0
        last edited by

        @Ron-Ball-0 said in Need Regex to Delete HTML attribute:

        title=“something” AND title=“link #2”

        You haven’t explained it very well. If the text is exactly what you show then just use the replace function with search mode normal. There is no need for a regex.

        If on the other hand “something” could be anything and “link #2” also anything please advise us so.

        Terry

        Ron Ball 0R 1 Reply Last reply Reply Quote 1
        • Ron Ball 0R
          Ron Ball 0 @Terry R
          last edited by

          @Terry-R Sorry, yes, the values between the quotes can be anything … numbers, letters, a mix, etc. anything except another quote! And I actually have hundreds of links in my file to “clean” … each one has a different “TITLE”.

          Lycan ThropeL 1 Reply Last reply Reply Quote 0
          • Lycan ThropeL
            Lycan Thrope @Ron Ball 0
            last edited by Lycan Thrope

            @Ron-Ball-0 ,
            Since you’ve clarified, you can try this regex to find and then delete the contents. Mind you, the html will still be there, but the actual thing you asked for, will not be.

            Find What = (title=".*")
            Replace With = blank
            Search Mode = REGULAR EXPRESSION
            Dot Matches Newline = NOT CHECKED

            Here’s a screenshot of what it looks like working. The first example one I found in the search, I replaced with the empty replace, and you see the result. The second example is still intact since I didn’t select to replace it, yet.

            htmltitledelete.PNG

            Ron Ball 0R 1 Reply Last reply Reply Quote 3
            • Ron Ball 0R
              Ron Ball 0 @Lycan Thrope
              last edited by

              @Lycan-Thrope That is perfect! I can’t believe it was so small … I’ve been searching and trying so many different things.

              1 Reply Last reply Reply Quote 1
              • Mark OlsonM
                Mark Olson
                last edited by

                Lycan-Thrope’s response is adequate for your needs as stated, and has the added bonus of being (probably) fast to execute and easy to understand.

                But if you’re curious, here’s an alternative that minimizes side-effects:
                replace (<a[^>]*?)\s*title\s*=\s*".*?"([^>]*?>) with \1\2.

                Before:

                <a href="fjoenr" title="oenrwn"><i title="eorn">eron</i></a>
                <a title = "eroeno">foenfeonf title="eoeno"</a>
                <p>title="Ereoneorn"</p>
                <a href="eoenoen"></a>title="eoenon"
                <a title="eoenon" href="eoenroenro">""</a>
                

                After:

                <a href="fjoenr"><i title="eorn">eron</i></a>
                <a>foenfeonf title="eoeno"</a>
                <p>title="Ereoneorn"</p>
                <a href="eoenoen"></a>title="eoenon"
                <a href="eoenroenro">""</a>
                
                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors