4
NewbieNewbie
4

    Oct 01, 2006#16

    I tried it and I think it worked. Let me know if this sounds correct.

    ==============================
    Select the text you want to use as your find.
    Click on Copy Selection to Clipboard button.
    Select the text you want to paste.

    Click on SEARCH
    Click on REPLACE IN FILES
    Enter ^c in the find box.
    Enter ^s in the replace box.
    ==============================

    It appeared to work. I am going to test it more before using it for real

    Please comment if I left anything out.

    Thank you again!
    dk

    6,624550
    Grand MasterGrand Master
    6,624550

      Oct 01, 2006#17

      You have perfectly understood how to do the block replaces. Take care with the format of your HTML files. If all are DOS files, no problem. If all are UNIX files, disable the configuration option Automatically convert to DOS format before loading an HTML file and executing the posted procedure.
      Best regards from an UC/UE/UES for Windows user from Austria

      1
      NewbieNewbie
      1

        Jan 31, 2007#18

        Hello, I am trying to search/replace (in files) over multiple lines where I don't know for sure how many lines there are. How can I do this when none of the wildcard characters apply to newline? Can anyone help me with the syntax?

        Code: Select all

        <script>
        ....
        ....
        ....
        </script>
        
        Thank You,

        Bill

        6,624550
        Grand MasterGrand Master
        6,624550

          Feb 01, 2007#19

          Try <script>[~<]+</script> (UltraEdit style)!

          This works only if there is no < inside the script block. And make backups of all your files because usage of [~<]+ is very dangerous here. Better would be to find/use a more complex regular expression which contains as much fixed text as possible to avoid replacing too much.
          Best regards from an UC/UE/UES for Windows user from Austria

          1
          NewbieNewbie
          1

            Feb 15, 2007#20

            I have similar requirement where my text looks like

            /************
            ...
            ...
            ...
            ...
            ************/

            I need to search and replace multiple lines starting with /* and ending with */. The challenge is that '*' is a regular expression symbol in UE.

            Thanks in advance,
            tengiz

            6,624550
            Grand MasterGrand Master
            6,624550

              Feb 15, 2007#21

              No problem, escape the asterisk character *. You can use, for example, following search string with using the UltraEdit regular expression syntax:

              %[ ^t]++/^*^*^*+[~*]+^*^*^*+/[ ^t]++^p

              %[ ^t]++ means from start of a line with 0 or more spaces or tabs.

              /^*^*^*+ followed by /*** and more *.

              [~*]+ all characters except *. That means it will not work if there is a block comment which contains a * inside the comment.

              ^*^*^*+/ followed by *** and more * before character /.

              [ ^t]++^p matches possible existing trailing spaces and tabs and the DOS line termination.

              But the better and more secure method to delete blocks with a defined start and end string, but undefined text between is to use a macro with the find select feature. Example macro which needs macro property Continue if a Find with Replace not found checked.

              Code: Select all

              InsertMode
              ColumnModeOff
              HexOff
              Top
              Loop 
              Find "/***"
              IfNotFound
              ExitLoop
              EndIf
              Key HOME
              IfColNumGt 1
              Key HOME
              EndIf
              StartSelect
              Find Select "***/"
              IfSel
              Delete
              EndSelect
              DeleteLine
              Else
              EndSelect
              ExitLoop
              EndIf
              EndLoop
              Top
              The macro above contains some extra code for security. For your example the following simplified macro would do also the job:

              Code: Select all

              InsertMode
              ColumnModeOff
              HexOff
              Top
              Loop 
              Find "/***"
              IfNotFound
              ExitLoop
              EndIf
              StartSelect
              Find Select "***/"
              Delete
              EndSelect
              DeleteLine
              EndLoop
              Top
              Best regards from an UC/UE/UES for Windows user from Austria

              3
              NewbieNewbie
              3

                Apr 27, 2022#22

                Hi guys,

                I've spent more than a few hours trying to solve something that should be simple, but is beyond me. Perhaps you can help me out?

                I have more than a few HTML files in which I would like to selectively replace some text.

                The original I have is:

                Code: Select all

                <a class="galpop-single" href="/img/full-size/AA1.webp">
                                 <img id="m-first" src="/img/thumbs/AA1-t.webp" width="420px" height="275px"  alt="description" title="" />
                </a>
                I would like it to wind up like this:

                Code: Select all

                <a class="galpop-single" href="/img/full-size/AA1.webp">
                                    <picture>
                                                <source srcset="/img/thumbs/AA1-t.webp" type="image/webp">
                                                <source srcset="/img/thumbs/AA1-t.jpg" type="image/jpeg">
                                                <img id="m-first" src="/img/thumbs/AA1-t.webp" width="420px" height="275px"  alt="description" title="" />
                                    </picture>
                </a>
                I've tried finding this:

                Code: Select all

                <a class="galpop-single" href="^(*^).webp">^p%[^t]++<img^(*^)>
                Then replace string is this:

                Code: Select all

                <a class="galpop-single" href="^1.webp">
                                    <picture>
                                                <source srcset="^1.webp" type="image/webp">
                                                <source srcset="^1.jpg" type="image/jpeg">
                                                <img^2>
                                    </picture>
                </a>
                But it hasn't worked, and neither have a myriad of other attempts.

                Any suggestions?

                6,624550
                Grand MasterGrand Master
                6,624550

                  Apr 27, 2022#23

                  There is used the UltraEdit regular expression syntax. So make sure to have UltraEdit selected as regular expression engine and not Unix or Perl.

                  The UltraEdit regular expression search string for this replace task is:

                  Code: Select all

                  ^(<a class="galpop-single" href="/img/full-size/^)^(?+^)^(.webp">^)[^t ]++^p[^t ]++^(<img id="m-first" src="*.webp"*/>^)
                  The UltraEdit regular expression replace string for this replace task is:

                  Code: Select all

                  ^1^2^3^p                    <picture>^p                                <source srcset="/img/thumbs/^2-t.webp" type="image/webp">^p                                <source srcset="/img/thumbs/^2-t.jpg" type="image/jpeg">^p                                ^4^p                    </picture>
                  Note: ^p matches a DOS/Windows line ending, i.e. carriage return + line-feed. There must be replaced all ^p by ^n in search and replace regular expression strings if the HTML files use Unix line endings, i.e. just line-feed.

                  The indents are with spaces according to the expected result example. There can be used in the replace string also ^t for a horizontal tab character one or more times instead of a series of spaces.
                  Best regards from an UC/UE/UES for Windows user from Austria

                  18572
                  MasterMaster
                  18572

                    Apr 27, 2022#24

                    Hi,

                    I tested this Perl regex Replace in UE 2022.0.0.102.

                    Find what:

                    Code: Select all

                    (<a class="galpop-single" href="(.+)\.webp">)\r\n[ \t]*<img (.+)>$
                    Replace with:

                    Code: Select all

                    $1
                                        <picture>
                                                    <source srcset="$2.webp" type="image/webp">
                                                    <source srcset="$2.jpg" type="image/jpeg">
                                                    <img $3>
                                        </picture>
                    BR, Fleggy

                    3
                    NewbieNewbie
                    3

                      Apr 28, 2022#25

                      That is awesome, thank you both Mofi and Fleggy. It solves the problem beautifully.

                      Can you help with a small addition if you would be so kind? Sometimes the original trailing text after <img is not formatted properly and broken into a few lines like this and the search doesn't find it due to the additional tabs and returns:

                      Code: Select all

                      <a class="galpop-single" href="/img/full-size/AA1.webp">
                                                      <img id="m-first" src="/img/thumbs/AA1-t.webp" 
                                                      alt="description"
                                                      title="" width="420px" height="263px"/>  
                      </a>

                      I've tried revising both your codes, but again failed. Can you help one more time?

                      6,624550
                      Grand MasterGrand Master
                      6,624550

                        Apr 28, 2022#26

                        Change the UltraEdit regular expression search string to:

                        Code: Select all

                        ^(<a class="galpop-single" href="/img/full-size/^)^(?+^)^(.webp">^)[^t ]++^p[^t ]++^(<img id="m-first" src="*"^)[^n^r^t ]+^(alt="*"^)[^n^r^t ]+^(title="*/>^)
                        Change the UltraEdit regular expression replace string to:

                        Code: Select all

                        ^1^2^3^p                    <picture>^p                                <source srcset="/img/thumbs/^2-t.webp" type="image/webp">^p                                <source srcset="/img/thumbs/^2-t.jpg" type="image/jpeg">^p                                ^4 ^5 ^6^p                    </picture>
                        That modified UltraEdit search/replace regular expressions work for both variants.

                        The Perl regular expression search string suggested by Fleggy can be modified to:

                        Code: Select all

                        (<a class="galpop-single" href="(.+)\.webp">)\r\n[ \t]*<img ([^>]+?)>
                        The Perl regular expression replace string suggested by Fleggy does not need a modification with this search expression working also for both variants.
                        Best regards from an UC/UE/UES for Windows user from Austria

                        3
                        NewbieNewbie
                        3

                          Apr 28, 2022#27

                          Absolutely fantastic. Thank you.

                          Read more posts (-3 remaining)