Community
    • 登入

    Regex: Copy text between one html file to more html files (from a folder to another)

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    13 貼文 5 Posters 924 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • guy038G
      guy038
      最後由 guy038 編輯

      Hi, @robin-cruise, @alan_kilborn, @peterjones and all,

      So, Robin, if I fully understand you, you would like to replace any zone <!-- PART1 -->•••••••••<!-- PART2 --> in all HTML files of the sub-folder folder 2 with the zone, below :

      <!-- PART1 -->
            <div class="Field">
                <div align="right">
                    TEXT TEXT A A A
                </div>
            </div>
      <!-- PART2 -->
      

      If I’m right about it, that’s rather easy with regexes :

      • Backup all your HTML files of folder 2 within an other folder ! ( A common sense action ! )

      • Open the Find in Files dialog ( Ctrl + Shift + F )

        • SEARCH (?s-i)<!-- PART1 -->.+?<!-- PART2 -->

        • REPLACE <!-- PART1 -->\r\n <div class="Field">\r\n <div align="right">\r\n TEXT TEXT A A A\r\n </div>\r\n </div>\r\n<!-- PART2 -->

        • FILTERS *.html

        • DIRECTORY The ABSOLUTE location of "folder 2"

        • Select the Regular expression search mode

        • Click on the Replace in Files dialog

        • Hit the OK button of the Are you sure? dialog


      So, @alan-kilborn and @peterjones, in this specific case, the goal to reach seems still possible with regexes ;-))

      Best Regards,

      guy038

      Terry RT 1 條回覆 最後回覆 回覆 引用 1
      • Terry RT
        Terry R @guy038
        最後由 編輯

        @guy038 said in Regex: Copy text between one html file to more html files (from a folder to another):

        in this specific case, the goal to reach seems still possible with regexes ;-))

        Actually I think you missed the statement that file1.html (in 1 folder) contains the source “code” that needs replacing a “no code present” area contained within many files in a different folder. Hence as the others mentioned, working with 2 files simultaneously, which regex is not capable of doing.

        I had considered mentioning that appending file1.html to ALL the other files, then the “Find in Files” option (with a suitable regex) would be able to:

        1. move the code to the new location and
        2. remove the remainder of the file1.html string that was appended.
          But then I thought this is far more work than his already thought about (and supplied) powershell solution.

        Terry

        1 條回覆 最後回覆 回覆 引用 0
        • guy038G
          guy038
          最後由 guy038 編輯

          Hi, @robin-cruise, @terry-r, @alan-kilborn, @peterjones and all,

          @terry-r :

          Many thanks for your comments However, I’m sorry as I still don’t see in which way I’m wrong :-((

          @robin-cruise said :

          So the content between <!-- PART1 --> to <!-- PART2 --> in file1.html needs be copied in all html files in folder 2 at the same <!-- PART1 --> to <!-- PART2 --> place.

          In my regex S/R, the part of text to be copied from File1.html is placed in the replace zone :

          • REPLACE <!-- PART1 -->\r\n <div class="Field">\r\n <div align="right">\r\n TEXT TEXT A A A\r\n </div>\r\n </div>\r\n<!-- PART2 -->

          and will replace, as @robin-cruise said, the same <!-- PART1 -->•••••••<!-- PART2 --> area in all files of folder 2 with the search zone :

          • SEARCH (?s-i)<!-- PART1 -->.+?<!-- PART2 -->

          So, I’m missing something obvious ! Could someone enlightens me with a short file1.html text, supposed to be in folder 1 and a short file2.html text, supposed to be in folder 2 ? TIA !

          BR

          guy038

          1 條回覆 最後回覆 回覆 引用 0
          • Terry RT
            Terry R
            最後由 編輯

            @guy038 said in Regex: Copy text between one html file to more html files (from a folder to another):

            So, I’m missing something obvious !

            Your solution involves grabbing the “source” first, then using that in the 2nd step which is the replacement using Find in Files. The OP was asking whether regex can simultaneously grab the source data, then edit the “other” files and insert it into all those files. So his request was to “open” 2 files together and “regex” them.

            Of course your solution would work if the “source code” is short enough.

            Terry

            1 條回覆 最後回覆 回覆 引用 1
            • guy038G
              guy038
              最後由 guy038 編輯

              Hi, @robin-cruise, @terry-r, @alan-kilborn, @peterjones and all,

              Ah…yes, I see what you mean, Terry !


              Now, let’s imagine that Notepad++ has these two new native features ( just a dream !! ) :

              • A Mark in Files dialog, in the same way than the Find in Files dialog. So, we could just bookmark any <!-- PART1 -->•••••••<!-- PART2 --> area, in all HTML files of folder 2, with, of course, the option Purge for each search ticked

              • A Bookmark in Files dialog, too. So, we could :

                • Select and copy the specific <!-- PART1 -->•••••••<!-- PART2 --> section of File1.html in the clipboard with Ctrl + C

                • Then, run the Search > Mark > Paste to (Replace) bookmarked lines option, in all HTML files of folder 2

              Best Regards,

              guy038

              Alan KilbornA 1 條回覆 最後回覆 回覆 引用 0
              • Robin CruiseR
                Robin Cruise
                最後由 編輯

                此回覆已被刪除!
                1 條回覆 最後回覆 回覆 引用 0
                • Robin CruiseR
                  Robin Cruise
                  最後由 編輯

                  thanks @guy038 Beautiful !

                  1 條回覆 最後回覆 回覆 引用 0
                  • guy038G
                    guy038
                    最後由 guy038 編輯

                    Hello, @robin-cruise, @terry-r, @alan-kilborn, @peterjones and all,

                    Well, I just realize this morning, that I’m wrong again, in my previous post. :-((

                    Indeed, as several consecutive lines would be marked, the Search > Mark > Paste to (Replace) bookmarked lines option would replace any bookmarked line with clipboard contents ! whereas the paste action should occur, once only, replacing all the lines bookmarked !

                    As a conclusion, this kind of operation, between files, cannot be achieved with regexes, as @peterjones and @alan-kilborn stated, previously !

                    BR

                    guy038

                    1 條回覆 最後回覆 回覆 引用 0
                    • Alan KilbornA
                      Alan Kilborn @guy038
                      最後由 編輯

                      @guy038 said in Regex: Copy text between one html file to more html files (from a folder to another):

                      has these two new native features ( just a dream !! )

                      Keep in mind that these “dream” features would have to be “Mark in All Opened Documents” and “Bookmark in All Opened Documents”…and thus the files in question would all have to be open in Notepad++.

                      The reason is that bookmarks and marks from marking are not saved with a file, so if a file was not open, there would be no remembering.

                      I know it was just a fantasy, but sometimes we have to do a little grounding of fantasy. :-)

                      1 條回覆 最後回覆 回覆 引用 1
                      • guy038G
                        guy038
                        最後由 編輯

                        Hi, @alan-kilborn and All,

                        I really should have thought a bit more, before answering ! Indeed, Alan, although the bookmarks are kept in the session.xml configuration file, there are not stored in files themselves. So, as soon as a file containing bookmarks is closed, these bookmarks are gone away the next time the file is opened, during a new N++ session !

                        Sorry for all that noise !

                        Cheers,

                        guy038

                        1 條回覆 最後回覆 回覆 引用 0
                        • 第一個貼文
                          最後的貼文
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors