Community
    • Login

    Search++: A work in progress

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    232 Posts 13 Posters 115.5k Views 3 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.
    • CoisesC Online
      Coises @guy038
      last edited by

      @guy038 said:

      Do you think it would be possible to add this feature to Search++ as part of the plugin’s future development ?

      I do think it would be possible, and that it would be a useful enhancement.

      I haven’t studied the problem in detail yet. The relevant concepts exist and are well-defined: Unicode canonical equivalence and compatibility equivalence. Probably someone has already implemented practical searches using canonical and compatibility equivalence in open source code, so finding and studying existing, mature solutions that have already encountered and resolved whatever complications inevitably arise will no doubt be my first step.

      1 Reply Last reply Reply Quote 1
      • CoisesC Online
        Coises @sevem47
        last edited by

        @sevem47 said:

        I think there is a small visual glitch in search/replace history

        Yes, that is an error. Thank you for catching and reporting it! I will find the cause and fix it.

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

          Hello, @coises, @thomas-knoefel and All,

          For some obscure reasons, one day, my usual USB key for tests was just considered as containing RAW text. I did not even succeeded to reformat it ! So I threw it in the trash and from a ( not too old ) copy of that key, I was able more or less, to reconstruct the original contents of this USB drive !


          Now, when I asked Google about “softwares able to search canonical and compatibility Unicode characters”, the IA answer, at the beginning, proposed, among other things, the CLI software ripgrep (rg). Although it does not seem to really treat canonical and compatibility Unicode forms AFAIK, it is quite fast and has plenty of interesting options !

          Refer to https://github.com/BurntSushi/ripgrep. The last release is version 16.0 . Download, preferably, the ripgrep-16.0.0-x86_64-pc-windows-msvc.zip archive which is compatible with 64-bit Windows 11 laptops

          After extraction of the rg.exe software, in a CMD window, run rg -h for short descriptions or rg --help for more details !


          Following my usual procedure, I searched for any file, including binary ones as well, of my new USB key, the string Fi, with this exact case, in regex mode and I got these results :

          Search "Fi" (32 189 hits in 624 files of 1 119 searched) [RegEx: Case]  with native N++ v8.9.9.1
          
          Search "Fi" (32 189 hits in 624 file(s)) [1 119 file(s) searched]       with MultiReplace v6.2.0.38
          
          32 189 matches in 624 of 1 118 files (Regex, match case): Fi            with Search++ v0.8 (x64)
          
          And running the DOS command "rg -a --stats Fi", it displayed, at the end :
          
          32189 matches
          24492 matched lines
          624 files contained matches
          1118 files searched
          12462212 bytes printed
          498369521 bytes searched
          0.173930 seconds spent searching
          0.573693 seconds total
          

          As you can see, the count of matches and the files concerned are identical for these 4 tests However, the number of files analyzed varies :

          • 1,119 for N++ and MultiReplace

          • 1,118 for Search++ and rg.exe

          I figured out why ! On my D: key, I have only :

          • One directory which is hidden : System Volume Information

          • One file which is hidden : Thumbs.db

          As the Hidden folders option was unchecked, N++ and MultiReplace did not consider the folder System Volume Information but did take in account the Thumbs.db file !

          Whereas, the Search++ plugin and the rg software did not consider, both, hidden files AND folders. Thus, it did not analyse the Thumbs.db, as well !

          Consequently, @coises, I suppose that you have enough place to modify the label of the option from Hidden files to Hidden files and folders. Alternatively, you could also decide to add a new option Hidden folders. Do as you like !


          Now, I ran the same tests again, on txt files ONLY and there are the results :

              •==============•==========•========•===========•===============•===============•==========================•
              |   Software   |   Hits   |  In    |  Scanned  |  First Time   |  Second Time  |        Command           |
              |   / Plugin   |          | Files  |   Files   | After Restart |  Right after  |                          |
              •==============•==========•========•===========•===============•===============•==========================•
              |   Notepad++  |  10600   |  311   |    641    |   17 s 25 "   |    5 s 32 "   |                          |
              •--------------•----------•--------•-----------•---------------•---------------•--------------------------•
              | MultiReplace |  10600   |  311   |    641    |   11 s 80 "   |    1 s 78 "   |                          |
              •--------------•----------•--------•-----------•---------------•---------------•--------------------------•
              |   Search++   |  10600   |  311   |    641    |   16 s 94 "   |    0 s 66 "   |                          |
              •--------------•----------•--------•-----------•---------------•---------------•--------------------------•
              |    rg.exe    |  10600   |  311   |    641    |   16 s 69 "   |    0 s 55 "   |  rg -a -ttxt --stats Fi  |
              •==============•==========•========•===========•===============•===============•==========================•
          

          Best Regards,

          guy038

          P.S. : Please note that the tests were all conducted BEFORE I wrote this post, which, obviously, modify the results !

          CoisesC 1 Reply Last reply Reply Quote 1
          • CoisesC Online
            Coises @guy038
            last edited by

            @guy038 said:

            Refer to https://github.com/BurntSushi/ripgrep.

            An interesting and sophisticated piece of software. It is written in Rust and by default uses that language’s regular expression search engine, which is a “finite state machine” implementation rather than a “backtracking” implementation. The practical effect of that is that the default engine doesn’t support lookarounds or backreferences, though it does support some constructs Boost::regex does not. It also avoids the “complexity” error that can occur during matching with Boost::regex. (The expression itself can still be “too complex,” but if it is, that’s known before matching ever begins.)

            One of the “someday…” wishes I have for Search++ is to add an alternate regex engine that uses a finite state machine (e.g., RE2), for use when the search expression doesn’t need backtracking-only features but the total space to be searched is huge.

            Consequently, @coises, I suppose that you have enough place to modify the label of the option from Hidden files to Hidden files and folders. Alternatively, you could also decide to add a new option Hidden folders.

            Yes, I see I should be more clear. Without thinking about it, I always assumed that if you were excluding “hidden” anything, that meant both hidden files and anything that could only be reached through a hidden folder. I hadn’t realized that Notepad++’s native search would still search hidden files if that box was not checked, so long as they weren’t in a hidden folder.

            I’m curious whether you, or anyone, foresees practical cases in which you would want to omit one from a search but not the other.

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

              Hi, @coises and All,

              You said :

              The practical effect of that is that the default engine [ of rg.exe ] doesn’t support lookarounds or backreferences …

              Well, actually, if you choose the --pcre2 option, it does support them ! For example :

              The rg -a -t txt --stats Fi(?=le) DOS command returns :

              C:\>d:
              
              D:\>rg -a -t txt --stats Fi(?=le)
              rg: regex parse error:
                  (?:Fi(?=le))
                       ^^^
              error: look-around, including look-ahead and look-behind, is not supported
              
              Consider enabling PCRE2 with the --pcre2 flag, which can handle backreferences
              and look-around.
              
              D:\>
              

              And, indeed, the command rg -a -t txt --stats --pcre2 Fi(?=le), after a restart, is quite functional and give these results :

              2250 matches
              1596 matched lines
              104 files contained matches
              642 files searched
              271490 bytes printed
              88413019 bytes searched
              130.606157 seconds spent searching
              17.113812 seconds total
              

              Note that I do not understand why the total search took about 17 s and the search, itself, took about 130 s ? But this is an off-topic question !


              Then, the next step, to my mind, was to try, for example, the regexes :

              (?=[[=O=]])\X(?=[[=u=]])\X(?=[[=r=]])\X(?=[[= =]])\X(?=[[=f=]])\X(?=[[=r=]])\X(?=[[=i=]])\X(?=[[=e=]])\X(?=[[=n=]])\X(?=[[=d=]])\X(?=[[= =]])\X(?=[[=S=]])\X(?=[[=a=]])\X(?=[[=r=]])\X(?=[[=u=]])\X(?=[[=n=]])\X(?=[[=a=]])\X(?=[[=s=]])\X
              (?=[[=O=]])\X(?=[[=u=]])\X(?=[[=r=]])\X(?=[[= =]])\X(?=[[=f=]])\X(?=[[=r=]])\X(?=[[=i=]])\X(?=[[=e=]])\X(?=[[=n=]])\X(?=[[=d=]])\X(?=[[= =]])\X(?=[[=Š=]])\X(?=[[=a=]])\X(?=[[=r=]])\X(?=[[=ū=]])\X(?=[[=n=]])\X(?=[[=a=]])\X(?=[[=s=]])\X
              (?=[[=O=]])\X(?=[[=u=]])\X(?=[[=r=]])\X(?=[[= =]])\X(?=[[=f=]])\X(?=[[=r=]])\X(?=[[=i=]])\X(?=[[=e=]])\X(?=[[=n=]])\X(?=[[=d=]])\X(?=[[= =]])\X(?=[[=S=]])\X(?=[[=a=]])\X(?=[[=r=]])\X(?=[[=u=]])\X(?=[[=n=]])\X(?=[[=a=]])\X(?=[[=s=]])\X
              
              Our friend Sarunas
              Our friend Šarūnas
              Our friend Šarūnas
              

              And verify if EACH of these three regexes did match the three lines beginning with Our friend ..., right below !

              Alas, thrice alas ! The program returns the message :

              D:\>rg --stats --pcre2 (?=[[=O=]])\X(?=[[=u=]])\X(?=[[=r=]])\X(?=[[= =]])\X(?=[[=f=]])\X(?=[[=r=]])\X(?=[[=i=]])\X(?=[[=e=]])\X(?=[[=n=]])\X(?=[[=d=]])\X(?=[[= =]])\X(?=[[=Š=]])\X(?=[[=a=]])\X(?=[[=r=]])\X(?=[[=ū=]])\X(?=[[=n=]])\X(?=[[=a=]])\X(?=[[=s=]])\X Coises.txt
              rg: PCRE2: error compiling pattern at offset 12: POSIX collating elements are not supported
              
              D:\>
              

              Even this simple command, below, fails :

              D:\>rg --stats --pcre2 [[=q=]] Coises.txt
              rg: PCRE2: error compiling pattern at offset 9: POSIX collating elements are not supported
              
              D:\>
              

              You can verify this assumption, at the end of this page : https://www.regular-expressions.info/refcharclass.html

              7ea82473-ab89-4100-8ef8-37b0f0dbd412-image.jpeg


              Now, you said :

              I’m curious whether you, or anyone, foresees practical cases in which you would want to omit one from a search but not the other.

              Well, I do not need that distinction for myself ! It’s just that your excellent Search in Files dialog can already filter :

              • By folder

              • And /or by included extensions or excluded extensions or regex

              • And/or by size

              • And/or by date-type and date

              Thus, it seemed to me that you could also add these two separate options Hiden files and Hidden folders, in order that this dialog was even more flexible ! But, of course, do as you like ;-)

              Best Regards,

              guy038

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

                Hello, @coises and All,

                You said, in a previous post :

                I do think it would be possible, and that it would be a useful enhancement.

                I haven’t studied the problem in detail yet. The relevant concepts exist and are well-defined: Unicode canonical equivalence and compatibility equivalence. Probably someone has already implemented practical searches using canonical and compatibility equivalence in open source code,

                To my mind, we do not need the help of anyone to achieve such a feature. Of course, my statement seems a little pretentious, but consider this :


                In your Search++ plugin’s code, the ONLY thing you have to do, in order to use this fantastic improvement, would be :

                • When the Plain button is selected, to use this layout :
                 □ M̱atch case     □ Whole word only
                
                                  □ Matches all U̱nicode forms
                
                • When the Regex button is selected, to use this layout :
                 □ M̱atch case     □ Ḏot matches line breaks
                
                 □ Free spacing̱   □ Unicode word ḇoundaries ( greyed )
                
                • When the ICU button is selected, to use this layoout
                 □ M̱atch case     □ Ḏot matches line breaks
                
                 □ Free spacing̱   □ Unicode word ḇoundaries
                

                Thus, when the Search++ dialog is selected :

                  ALT + B  toggles 'Unicode word boundaries'  ( ICU mode )
                  ALT + D  toggles 'Dot matches line breaks   ( Regex / ICU mode )
                  ALT + G  toggles 'Free spacing'             ( Regex / ICU mode )
                  ALT + M  toggles 'Match case'               ( Plain / Regex / ICU mode )
                  ALT + U  toggles 'Match all Unicode forms'  ( Plain mode )
                  ALT + W  toggles 'Whole word only'          ( Plain mode )
                
                • Then, as long as, both, the Plain button and the Match all Unicode forms option are selected :

                • Switch INTERNALLY to the Regex mode

                • Replace, INTERNALLY, ANY character • of the text ( ABOVE \x001F and different from \R), within the search window, by the regex (?=[[=•=]])\X

                That’s all !


                One short example : internally, IF the search dialog contains :

                • The Sarun string, you would change it with the regex (?=[[=S=]])\X(?=[[=a=]])\X(?=[[=r=]])\X(?=[[=u=]])\X(?=[[=n=]])\X

                • The Šarūn string, you would change it with the regex (?=[[=Š=]])\X(?=[[=a=]])\X(?=[[=r=]])\X(?=[[=ū=]])\X(?=[[=n=]])\X

                • The Šarūn string, you would change it with the regex (?=[[=S=]])\X(?=[[=a=]])\X(?=[[=r=]])\X(?=[[=u=]])\X(?=[[=n=]])\X

                And you can verify that each of these three regexes do match the three strings Sarun, Šarūn and Šarūn , simultaneously !!

                Best Regards,

                guy038

                P.S. :

                • In the first string Sarun, NO character with an accent

                • In the second string Šarūn, two single chars with an accent ( Š and ū )

                • In the third string Šarūn, two characters with a base letter ( S and u ) followed with an accent ( ̌ and ̄ )

                CoisesC 1 Reply Last reply Reply Quote 0
                • CoisesC Online
                  Coises @guy038
                  last edited by

                  @guy038 said:

                  In your Search++ plugin’s code, the ONLY thing you have to do, in order to use this fantastic improvement, would be :

                  • When the Plain button is selected, to use this layout :
                   □ M̱atch case     □ Whole word only
                  
                                    □ Matches all U̱nicode forms
                  

                  Well, one immediate problem is that [[=x=]] doesn’t respect case, regardless of whether (?i) or (?-i) is in effect.

                  Beyond that, I’m thinking that there ought to be the ability to choose to match using canonical equivalence or compatibility equivalence. In fact, for plain text searches especially, I suspect canonical equivalence is what most people would expect. It probably should be the default.

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

                    Hello, @coises and All,

                    Could you enlighten me of a weird behaviour within your two plugins ColumnsPlusPlus and Search++ ?


                    we’ll try to use the (?s)^xyz.+|^abc.+ regex against this text, pasted in a new tab :

                    This is
                    a test
                    abc
                    with some text
                    to see
                    xyz
                    if everything
                    works properly
                    
                    • Place the caret at beginning of the 5th line to see

                    • Use the Replace All After in Whole Document option => The third last lines are deleted => OK

                    • Now, use the Replace All Before in Whole Document option => Message No match found before current position ! Why ? to my mind, the (?s)^xyz.+|^abc.+ regex should have matched the 3 lines :

                    abc
                    with some text
                    to see
                    

                    Of course, if we use, instead, the Replace All in Whole Document option, it does delete these three lines !


                    A similar behaviour occurs with the ColumnPlusPlus plugin. I use this layout :

                    35f2aab7-60eb-48cc-be10-7ab68e9458f8-image.jpeg

                    • Place the caret at beginning of the 5th line to see

                    • Use the Replace After option => The third last lines are deleted, all the remaining text is colored with the custom style and the message One replacement made is displayed => OK

                    • Now, use the Replace Before option => we get the message No match found, with all text still in custom style

                    34368dea-f211-416d-a596-bf2328335155-image.jpeg

                    Of course, if we use, instead, the Replace All option it does delete the three lines from string abc

                    Best Regards,

                    guy038

                    P.S. :

                    See also the end of this post : https://community.notepad-plus-plus.org/post/106889

                    CoisesC 1 Reply Last reply Reply Quote 0
                    • CoisesC Online
                      Coises @guy038
                      last edited by

                      @guy038 said:

                      • Now, use the Replace All Before in Whole Document option => Message No match found before current position ! Why ? to my mind, the (?s)^xyz.+|^abc.+ regex should have matched the 3 lines :
                      abc
                      with some text
                      to see
                      

                      Matching before and after are defined as:

                      • Before applies the command action only to matches that occur to the left and upward in the active document relative to the current position or selection. The action is not applied to matches which overlap the current position or selection.

                      • After applies the command action only to matches that occur to the right and downward in the active document relative to the current position or selection. The action is not applied to matches which overlap the current position or selection.

                      It could be that this is not what people expect, which might indicate a design problem. I will have to consider that.

                      The commands do not match “within the part of the document that occurs before or after the caret or selection”; they match within the whole document, accepting only matches which occur entirely before or after the current position or selection. Since the current position in your example is within the matched text, that match is not considered to be “before” the current position.

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

                        Hi, @coises,

                        Oh… I see ! So using the same text below and the same regex ( (?s)^xyz.+|^abc.+ ) of my previous post :

                        This is
                        a test
                        abc
                        with some text
                        to see
                        xyz
                        if everything
                        works properly
                        
                        • First, I placed the caret at beginning of the 5th line to see. As NO colored zone exists, the whole document was supposed to be the scope !

                        • Using the Replace After option => The third last lines were deleted and the message One replacement made was displayed

                        • Moreover, the entire lines, with their line-breaks, were colored with the custom style => OK

                        • Then I placed the caret at end of the fifth line, between the word see and its line-break

                        • After running the Replace Before option => I got the message No matches found. This is the expected behavior as the caret is INSIDE the colored zone and scope !

                        • Finally, I placed the caret at the beginning of the virtual line 6, so OUTSIDE the colored zone

                        • After running the Replace Before option, again => The three lines, beginning with the string abc, were deleted and the message One replacement made was displayed

                        BR

                        guy038

                        CoisesC 1 Reply Last reply Reply Quote 0
                        • CoisesC Online
                          Coises @guy038
                          last edited by

                          @guy038 said:

                          • Moreover, the entire lines, with their line-breaks, were colored with the custom style => OK

                          • Then I placed the caret at end of the fifth line, between the word see and its line-break

                          • After running the Replace Before option => I got the message No matches found. This is the expected behavior as the caret is INSIDE the colored zone and scope !

                          No, you are missing the point.

                          The custom style coloring is a consequence of how Columns++ Search in indicated region works. Columns++ is always doing the equivalent of what in Search++ would be a search in Marked Text. When there is no selection, nothing is marked and Auto set is checked, all text in the document is marked with the custom style. That isn’t the cause of the difference between what you’re seeing and what you expect.

                          Compare what happens if you do your original test with this expression instead:

                          (?-s)^xyz\R.+|^abc\R.+

                          In Columns++ you’ll see the coloring, in Search++ you won’t, but the results will be the same: both After and Before will work.

                          To see why your original expression didn’t work for Before, start fresh again, use your original expression, do Replace After and then do Select All (no Before).

                          Notice that the selected area includes where your caret was. That is why it isn’t considered to be a match Before the current position.

                          1 Reply Last reply Reply Quote 0

                          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