Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Searching for, marking and replace in one Line

    Help wanted · · · – – – · · ·
    4
    7
    90
    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 Rafflenbeul
      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
      • Ekopalypse
        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
        • guy038
          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

          Ekopalypse 1 Reply Last reply Reply Quote 2
          • Ekopalypse
            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 Kilborn 1 Reply Last reply Reply Quote 3
            • Alan Kilborn
              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!

              Ekopalypse 1 Reply Last reply Reply Quote 2
              • Ekopalypse
                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 Kilborn 1 Reply Last reply Reply Quote 1
                • Alan Kilborn
                  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
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors