Community
    • Login

    Search and replace question

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 263 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.
    • Tom DirksT
      Tom Dirks
      last edited by PeterJones

      Could you please help me with the following search-and-replace problem I am having?

      I am editing an html file and need to delete many of the hyperlinks.

      Here is the data I currently have (“before” data):

      <a name="pgfId-659225"></a><a name="TMS AEO alt_remote_control"></a><a name="alt_remote_control"></a><a name="TMS alt_remote_control"></a>alt_remote_control</h6>
      

      Here is how I would like that data to look (“after” data):

      <a name="pgfId-659225"></a><a name="alt_remote_control"></a><a name="TMS alt_remote_control"></a>alt_remote_control</h6>
      

      In other words, I want to delete the hyperlink whose name begins with “TMS AEO” and leave the other hyperlinks on that line intact.

      To accomplish this, I have tried using the following Find/Replace expressions and settings

      Find What = <a name="TMS AEO .+</a>
      Replace With = ``
      Search Mode = REGULAR EXPRESSION
      Dot Matches Newline = NOT CHECKED

      Unfortunately, this did not produce the output I desired, and I’m not sure why. It ended up selecting all of the hyperlinks on that line up to the last “</a>”. Could you please help me understand what went wrong and help me find the solution?

      PeterJonesP 1 Reply Last reply Reply Quote 2
      • PeterJonesP
        PeterJones @Tom Dirks
        last edited by PeterJones

        @Tom-Dirks said in Search and replace question:

        <a name="TMS AEO .+</a>
        

        Unfortunately, this did not produce the output I desired, and I’m not sure why. It ended up selecting all of the hyperlinks on that line up to the last “</a>”

        So very close! Great job

        The .+ is greedy, so it will match as many single characters as it can, which can include single characters that make up the hyperlinks between. If you make it non-greedy by adding a ? to make that .+?, it will stop the match at the first </a> instead of the last </a>: Thus, <a name="TMS AEO .+?</a> should work for you

        ----

        Useful References

        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        Tom DirksT 1 Reply Last reply Reply Quote 4
        • Tom DirksT
          Tom Dirks @PeterJones
          last edited by

          @PeterJones That worked! Thank you very much.

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