Community
    • Login

    Auto Find and Replace 6 Keywords in a Script between to different pages

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    15 Posts 5 Posters 1.3k 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.
    • PeterJonesP
      PeterJones @Wilderlore
      last edited by

      @Wilderlore said in Auto Find and Replace 6 Keywords in a Script between to different pages:

      yep I’m still around and would appreciate any help.

      Unfortunately, you gave us no new information, so you did nothing to help us understand the changes you want to make. As a result, we still cannot help you.

      ----

      Useful References

      • Please Read Before Posting
      • Template for Search/Replace Questions
      • Formatting Forum Posts
      • FAQ: Where to find regular expressions (regex) documentation
      • Notepad++ Online User Manual: Searching/Regex
      1 Reply Last reply Reply Quote 0
      • WilderloreW
        Wilderlore @Alan Kilborn
        last edited by

        @Alan-Kilborn
        Would you mind telling me what is the source of confusion then?

        My objective is to easily find and replace those 6 keywords while eliminating the potential human error of messing up the rest of the script. I am not too knowledgeable about this subject, so I apologize for not knowing where the confusion is.

        If you are familiar with the camera add-on in excel, it basically duplicates the table on one tab and any chnage made on the original table will be replicated on the copy table on a 2nd tab. I’m looking for something similar in Notepad ++

        PeterJonesP 1 Reply Last reply Reply Quote 0
        • guy038G
          guy038
          last edited by guy038

          Hello @wilderlore, @neil-schipper, @peterjones and All,

          I tried to guess what your goal is ! So, this is my first try :


          From this INPUT file :

          'ITEM A
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_NAME
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_START_DATE
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_END_DATE
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_TIME
          TAG POS=3 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=3 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_ID
          TAG POS=2 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_NEW
          
          'ITEM B
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_NAME
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_START_DATE
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_END_DATE
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_TIME
          TAG POS=3 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=1 xxxxxxxxxxxxxxxxxxxxxx
          TAG POS=3 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_ID
          TAG POS=2 xxxxxxxxxxxxxxxxxxxxxx ITEM_1_NEW
          

          Do you expect the following OUTPUT text :

          'ITEM A
          =ITEM_1_NAME
          =ITEM_1_START_DATE
          =ITEM_1_END_DATE
          =ITEM_1_TIME
          =ITEM_1_ID
          =ITEM_1_NEW
          
          'ITEM B
          =ITEM_1_NAME
          =ITEM_1_START_DATE
          =ITEM_1_END_DATE
          =ITEM_1_TIME
          =ITEM_1_ID
          =ITEM_1_NEW
          

          In this case, it’s easy with regular expressions ! Here is a possible solution :

          • Open your file in Notepad++

          • Open the Replace dialog ( Ctrl + H )

          • SEARCH (?-si)(?|^TAG POS.+?( ITEM_.+)?(?:\R|\z)|^('ITEM \u))

          • REPLACE ?1=\1\r\n    or    ?1\1\n if you work with UNIX files

          • Untick all box options

          • Tick the Wrap around option

          • Select the Regular expression search mode

          • Click once on the Replace All button

          Here you are : your text is now changed as below :

          'ITEM A
          = ITEM_1_NAME
          = ITEM_1_START_DATE
          = ITEM_1_END_DATE
          = ITEM_1_TIME
          = ITEM_1_ID
          = ITEM_1_NEW
          
          'ITEM B
          = ITEM_1_NAME
          = ITEM_1_START_DATE
          = ITEM_1_END_DATE
          = ITEM_1_TIME
          = ITEM_1_ID
          = ITEM_1_NEW
          

          Best Regards,

          guy038

          WilderloreW Neil SchipperN 2 Replies Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @Wilderlore
            last edited by

            @Wilderlore ,

            Notepad++, except during printing, has no concept of “on a different page”.

            If by “page” you mean “in a separate text file”, Notepad++ has no native way of reading the contents of one file, and using those contents to affect changes in another file. There are scripting solutions, if you have a scripting plugin, but I have no idea whether to suggest the one I’m thinking of to you or not, because you haven’t shown us enough to be able to really tell what you want.

            For example, when Guy just tried to guess what you wanted, I think he got it exactly backwards from the direction that I thought you wanted the transformation. That means that you haven’t even successfully told us which direction you want the transformation to go.

            That is why I linked you to some general-purpose and search-and-replace-specific information from the forum. If you at least gave us a good picture of the data “before” and “after” your transformation, we might have a chance. But if we cannot tell which is your “before” and which is your “after”, then there’s no hope that we can help you.

            1 Reply Last reply Reply Quote 1
            • WilderloreW
              Wilderlore @guy038
              last edited by

              @guy038

              Thank you so much! I think that is what I’m looking for! I will give it go next time!

              And sorry to everyone else for the confusion. I truly no nothing about coding, but I appreciate everyone’s patience!

              1 Reply Last reply Reply Quote 1
              • Neil SchipperN
                Neil Schipper @guy038
                last edited by Neil Schipper

                @guy038 Hi Guy, I enjoyed seeing the revert subexpression counter in each branch of an alternation construct ((?|) used in a real world problem, which is something I’ve never done, or even seen done as best as I can recall.

                But then I studied the expression for a bit, and got to wondering why it was necessary to match (and write back) the header lines (that start 'ITEM..). Anyway, I ran it, and was surprised to find that it does not produce exactly the stated desired output, and also doesn’t produce the sample output you provided, differing (very slightly) from both.

                Here’s what is produced when I run it:

                ='ITEM A
                
                = ITEM_1_NAME
                = ITEM_1_START_DATE
                = ITEM_1_END_DATE
                = ITEM_1_TIME
                = ITEM_1_ID
                = ITEM_1_NEW
                
                ='ITEM B
                
                = ITEM_1_NAME
                = ITEM_1_START_DATE
                = ITEM_1_END_DATE
                = ITEM_1_TIME
                = ITEM_1_ID
                = ITEM_1_NEW
                

                Again, the deviations are very slight: (1) a ‘=’ is placed before the header line, and (2) a space is added after ‘=’ in each body line. (As to whether these deviations impact whether the requirements of the original request are met, I have no Ouija board handy to determine that.)

                To produce the stated desired output, this simpler expression can be used:

                Fi: (?-si)^TAG POS.+?(\h(ITEM_.+))?(?:\R|\z)
                Re: ?2=\2\r\n

                In any event, thanks for giving me an excuse to shake out some cobwebs in my mind.

                @PeterJones Hi. In regard to the documentation of the so-called branch reset directive (I like my wordier name for it as per above), there are some issues. Most important are the errors in:

                Without the branch reset, (y) would be group 3, and (p(q)r) would be group 4 …

                Both of those group numbers are off by one (corrections are in example below).

                The other issues are minor: a stray forward slash in the line that includes the example expression / (?x) .., and, vertical misalignment of the helper comment line that shows the counts, and finally, a missed opportunity for helping a reader (like me) absorb the lesson (without having to read it 4 - 6 times).

                Here’s my suggested replacement text for the example section:

                For example, consider these two expressions that use alternations, the first one using normal branch counting (but uses (?: to skip one subexpression from being counted), and the second one using the branch-reset mechanism:

                #    -------------------no branch-reset-----------------
                (?x) ( a )  (?: x ( y ) z | (p (q) r) | (t) u (v) ) ( z )
                #      1   skip     2        3  4        5     6      7  <=== assigned subexpression counter values
                
                #              ---------branch-reset zone---------
                (?x) ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z )
                #      1   skip     2        2  3        2     3      4  <=== assigned subexpression counter values
                

                Two things to note about the latter case are:

                1. the branch-reset bounding subexpression does not get a count for itself.
                2. it’s possible that intermediate subexpressions won’t exist. In this case, the text axyzz matches using the first alternate, and subexpression 3 does not exist, and subexpression 4 does.

                It’s a bit longer than the original but the mechanism is quite subtle so I hope you’ll see fit to update the manual.

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

                  Hi @wilderlore, @neil-schipper, @peterjones and All,

                  @neil-schipper :

                  Oh yes , you’re perfectly right about it ! I just forgot this simple rule :

                  You never need, in your search regex, to involve lines which do not change between the INPUT and OUTPUT texts !

                  So, as I don’t have to take care about lines 'ITEM A, 'Item B …, the Branche Reset feature is useless and the regex can be simplified as you did :-))

                  In addition my version wrongly added an equal sign, at beginning of lines 'ITEM A, 'Item B …, as well as an extra line-break right after. My bad !


                  Now, regarding the N++ documentation, indeed, the lines :

                  #      before  ---------------branch-reset----------- after
                  / (?x) ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z )
                  #      1            2         2  3        2     3     4
                  
                  Without the branch reset, (y) would be group 3, and (p(q)r) would be group 4, and (t) would be group 5. With the branch reset, they both report as group 2
                  

                  should be changed as :

                  #    before --------------branch-reset------------- after
                  (?x) ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z )
                  #    1      x     2         2  3        2     3     4
                  
                  whereas the classical syntax is :
                  
                  #    -------------------no branch-reset------------------
                  (?x) ( a )  (?: x ( y ) z | (p (q) r) | (t) u (v) ) ( z )
                  #    1      x     2         3  4        5     6     7
                  
                  Without the branch reset, (y) would be group 2, (p(q)r) would be group 3, (q) would be group 4, (t) would be group 5 and so on.... With the branch reset, groups (y), (p...) and (t) both report as group 2
                  

                  Peter, don’t bother about the bold highlighting of some words, automatically created when you begin lines with 4 space chars !


                  Neil, you added :

                  2 it’s possible that intermediate subexpressions won’t exist. In this case, the text axyzz matches using the first alternate, and subexpression 3 does not exist, and subexpression 4 does

                  Nothing weird here ! As your axyzz string matches only the first alternative of the Branch Reset which does not involve the group 3 :

                  • The group 1, before the Branche Reset, is defined

                  • The group 2, within the first alternative of the Branche Reset, is defined

                  • The group 4, after the Branche Reset is defined

                  • The group 3, part of the other alternatives of the Branche Reset, is not defined

                  Best Regards,

                  guy038

                  PeterJonesP 1 Reply Last reply Reply Quote 0
                  • PeterJonesP
                    PeterJones @guy038
                    last edited by PeterJones

                    @guy038 , @neil-schipper,

                    I mentioned this to Neil in a private message, but should have posted it here for others, too: The PR#414 shows the changes I made. Do those look good to you?

                    Peter, don’t bother about the bold highlighting of some words, automatically created when you begin lines with 4 space chars !

                    FYI, you can convince the forum to not bold random words in code blocks.

                    Compare

                    ```
                    without the branch reset, (y) would be group 2, ...
                    ```
                    

                    rendering as

                    without the branch reset, (y) would be group 2, ...
                    

                    to

                    ```txt
                    without the branch reset, (y) would be group 2, ...
                    ```
                    

                    rendering as

                    without the branch reset, (y) would be group 2, ...
                    

                    If you use a known markdown-file-type after the opening ``` (or ~~~, if that’s your preferred character), then the forum doesn’t try to guess what programming language it is, instead using whatever you tell it. And telling it ```txt tells the forum to not do any formatting of the text.

                    (This is why Scott used to recommend ```z, because that also tells the Markdown it’s filetype “z”, which doesn’t exist, so the forum also doesn’t try to highlight it.)

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

                      @PeterJones said in Auto Find and Replace 6 Keywords in a Script between to different pages:

                      This is why Scott used to recommend ```z

                      I picked up that habit as well, but a slight downside is you get no background differentiation with it:

                      hello world
                      

                      This perhaps calls less attention to it…good thing or bad…I don’t know.

                      PeterJonesP 1 Reply Last reply Reply Quote 1
                      • PeterJonesP
                        PeterJones @Alan Kilborn
                        last edited by

                        @Alan-Kilborn said in Auto Find and Replace 6 Keywords in a Script between to different pages:

                        you get no background differentiation with it

                        Ah, right, I forgot that. So using the ```txt will keep it in the backgrounded box, whereas ```z will make it blend in more with normal text.

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