Community
    • Login

    Searching for, marking and replace in one Line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 4 Posters 773 Views 1 Watching
    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.
    • Daniel RafflenbeulD Offline
      Daniel Rafflenbeul
      last edited by

      Hello here… I coud need your help.
      I have the following line :
      <A HREF=“./pdfs/pics/1400_Days.jpg” target=“_gnnnfigte”>Bild</A>
      From this Line i would do the following :
      Searching for “<A HREF=”./pdfs/pics/"
      Marking the Text behind : (in every Line different) 1400_Days.jpg
      Searchin for “Bild”
      Replace Bild with :<img src="./pdfs/pics/THE-MARKED-TEXT"alt=“Bild” align=“middle” height=“80” width=“60”></A>

      So that after all the complete Line looks like this :

      <A HREF=“./pdfs/pics/1400_Days.jpg” target=“_gnnnfigte”><img src=“./pdfs/pics/1400_Days.jpg” alt=“Bild” align=middle height=“80” width=“60”></A>

      How can i get this , repeating for over 100 Lines ???

      regards Daniel

      1 Reply Last reply Reply Quote 0
      • EkopalypseE Offline
        Ekopalypse
        last edited by

        With the given data, one possible solution might be
        find what:<A HREF="\./pdfs/pics/.*">\KBild
        replace with:\<img src="\./pdfs/pics/1400_Days\.jpg" alt="Bild" align=middle height="80" width="60"\>
        check Regular expression

        Because of using the \K syntax it is needed to press replace all.

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

          Hello, @daniel-rafflenbeul, @ekopalypse and All,

          @ekopalypse, I don’t think the different backslash characters are necessary in the Replace zone !

          However, as @daniel-rafflenbeul said

          Marking the Text behind : (in every Line different) 1400_Days.jpg

          I suppose that we have to catch every picture’s name !.

          So, I propose the following regex S/R :

          SEARCH (?-s)<A HREF="\./pdfs/pics/(.+?").+>\KBild

          REPLACE <img src="./pdfs/pics/\1 alt="Bild" align="middle" height="80" width="60">

          with the options Wrap around and Regular expression checked and a click on the Replace All button, exclusively

          Best Regards,

          guy038

          EkopalypseE 1 Reply Last reply Reply Quote 2
          • EkopalypseE Offline
            Ekopalypse @guy038
            last edited by

            @guy038

            to be honest, I don’t know why I escaped < and >,
            maybe because I’m currently working on this.

            But for the special regex characters .[{}()\*+?|^$,
            I always escape them if they are used literally, just to be sure.
            Don’t know if this can bite me one day.

            Alan KilbornA 1 Reply Last reply Reply Quote 3
            • Alan KilbornA Offline
              Alan Kilborn @Ekopalypse
              last edited by

              @Ekopalypse said in Searching for, marking and replace in one Line:

              maybe because I’m currently working on this.

              +1 ! :-)

              I always escape them if they are used literally, just to be sure.

              or you could wrap them in \Q and \E, for a cleaner look as a side benefit!

              EkopalypseE 1 Reply Last reply Reply Quote 2
              • EkopalypseE Offline
                Ekopalypse @Alan Kilborn
                last edited by

                @Alan-Kilborn

                that’s really a nice one.
                \Q…\E is much easier than parsing through the string :-D

                Alan KilbornA 1 Reply Last reply Reply Quote 1
                • Alan KilbornA Offline
                  Alan Kilborn @Ekopalypse
                  last edited by

                  @Ekopalypse said in Searching for, marking and replace in one Line:

                  \Q…\E is much easier

                  and it is even easier if the regex string is intended to be all literal after a certain point. Just use \Q at that point an no “closing” \E is needed!

                  Example, find a minimal run of any characters followed by 3 literal *:

                  .*?\Q***

                  1 Reply Last reply Reply Quote 3

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors