Community
    • Login

    sample config

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    24 Posts 4 Posters 3.6k 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.
    • guy038G
      guy038
      last edited by guy038

      Hello, @justin-lang, @alan-kilborn, @peterjones, and All,

      Here is a second solution which uses the backtraking control verbs (*SKIP) and (*FAIL) or (*F)

      I assume that the goal is to list all file(s) that do not contain any entire line username •••• password ••••, whatever its case, when using :

      • The Find All in Current Document button, in the Find dialog

      • The Find All in All Opened Documents button, in the Find dialog

      • The Find All button, in the Find in Files dialog


      SEARCH \A(?s)(.*(?i)^username \S+ password \S+$(*SKIP)(*F)|.+?$)

      How this regex works ?

      • First note that there are two alternatives, separated with the | symbol

        • A) \A(?s).*(?i)^username \S+ password \S+$(*SKIP)(*F)

          • The part A tries to match any text from the very beginning ( \A ) of current file, till a entire line username •••• password ••••, whatever its case, ( (?i) )
        • B) \A(?s).+?$

          • The part B matches any text from the very beginning of current file ( \A ), till the first non-empty line,
            included ( (?s).+?$ )
      • So, from the very beginning of file, the regex engine begins to test the first alternative and tries to match an entire line username •••• password ••••

        • If such a line can be found, then :

          • The (SKIP) control verb, skips all this match and the working location is moved to right after the line username •••• password ••••.

          • The second control verb (*F) forces the regex engine to cancel this succesful match

          • So, the regex engine tries the second alternative \A(?s).+?$, which also fails, as the current location is not, anymore, at the very beginning of current file !

          • As no other alternative exists, the overall match attempt fails and no match has been found

        • If, from the very beginning, any text, ending with the entire line username •••• password ••••, cannot be found, further on, in current file, the first alternative is left and the regex engine tries the second alternative… which always succeeds :

          • The \A assertion is verified as the current location is still the very beginning of current file

          • And the part (?s).+?$ simply matches any text, from the very beginning, till the end of the first non-empty line


      Remark :

      • In order to test this regex against individual files, tick the Wrap around option and click on the Find Next button

      Best Regards,

      guy038

      Justin LangJ 1 Reply Last reply Reply Quote 2
      • guy038G
        guy038
        last edited by guy038

        Hi, @peterjones, @justin-lang, @alan-kilborn and All,

        Peter, I’m terribly sorry but I cannot get your regex (?i-s)\A(^.*\R(?!^username \S+ password \S+$))+\z to work properly :-((


        I’m using seven files from G1.txt to G7.txt with N++ v7.9.2

        • Contents of G1.txt, with the concerned line username •••• password •••• as line 1 :
        username blah password blah
        usexrname admin pasxsword cisco
        some other text
        
        • Contents of G2.txt, with the concerned line username •••• password •••• as line 2 :
        usexrname admin pasxsword cisco
        username blah password blah
        some other text
        
        • Contents of G3.txt, with the concerned line username •••• password •••• as line 3, without EOL chars
        usexrname admin pasxsword cisco
        some other text
        username blah password blah
        
        • Contents of G4.txt, with a first blank line and the concerned line username •••• password •••• as line 3
        
        usexrname admin pasxsword cisco
        username blah password blah
        some other text
        
        • Contents of G5.txt, without any line username •••• password •••• :
        usernxame blah paxssword blah
        usexrname admin pasxsword cisco
        some other text
        
        • Contents of G6.txt, with a first blank line and without any line username •••• password •••• :
        
        usernxame blah paxssword blah
        usexrname admin pasxsword cisco
        some other text
        
        • Contents of G7.txt, with the concerned text username •••• password ••••, surrounded by digits ( so NOT entire line )
        usexrname admin pasxsword cisco
        12345 username blah password blah 67890
        some other text
        
        • If I use my regex \A(?s)(.*(?i)^username \S+ password \S+$(*SKIP)(*F)|.+?$), I do find results which seem correct as the regex outputs, with filter G*.txt :

          • G5.txt and G6.txt which do not contain any entire line username •••• password ••••

          • G7.txt which contains text username •••• password •••• but surrounded with numbers

        48a38c46-4450-413c-b08a-5f713c5541f0-image.png


        • If I use your regex (?i-s)\A(^.*\R(?!^username \S+ password \S+$))+\z, I do not find any result !?

        30158fca-5cb9-4d0b-b78b-3d7c4a0a3e91-image.png

        Best Regards,

        guy038

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

          @guy038 said in sample config:

          I’m terribly sorry but I cannot get your regex (?i-s)\A(^.*\R(?!^username \S+ password \S+$))+\z to work properly :-((

          Like I said, that one had bad logic – eating up a whole line before comparing against the unwanted line. Though I’m not sure why you didn’t get any… When I try it with my bad regex, I matched some of the files correctly, but my pw.txt and your g1.txt were incorrectly matched, because they had the username/password line as the first line:
          9ca07fd6-cda0-44d8-8a0f-b0c6145500d9-image.png

          Compare to when I switch to my modified/corrected (?i-s)\A(^(?!username \S+ password \S+).*$\R*)+\z regex:
          f4704910-2919-4d2b-b66a-5cb1b46a4471-image.png

          Notepad++ v7.9.4   (64-bit)
          Build time : Mar 15 2021 - 01:03:10
          Path : C:\usr\local\apps\notepad++\notepad++.exe
          Admin mode : OFF
          Local Conf mode : ON
          OS Name : Windows 10 Enterprise (64-bit) 
          OS Version : 1903
          OS Build : 18362.1256
          Current ANSI codepage : 1252
          Plugins : ComparePlugin.dll ExtSettings.dll HexEditor.dll LuaScript.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppConsole.dll NppConverter.dll NppEditorConfig.dll NppExec.dll NppExport.dll NppFTP.dll NppUISpy.dll PreviewHTML.dll PythonScript.dll QuickText.dll TagLEET.dll XMLTools.dll 
          
          1 Reply Last reply Reply Quote 0
          • guy038G
            guy038
            last edited by guy038

            Hi, @peterjones,

            I still don’t understand why I do not get any results with your first version (?i-s)\A(^.*\R(?!^username \S+ password \S+$))+\z !?

            • Could it be related to enhancements in Npp v7.9.3 or v7.9.4 releases ( forbidden with XP machines )

            • Could it be related to the update of Scintilla ?

            • I don’t think that it happens because of Win XP itself ! Could you make a quick test to verify your first regex version with N++ v7.9.2. Thanks !


            Fortunately, your second version (?i-s)\A(^(?!username \S+ password \S+).*$\R*)+\z works nicely, as the picture, below, shows and finds the same files as my own regex. Pretty reassuring, isn’t it ?

            fd941129-e704-49f4-a905-c793528b4ec7-image.png

            BR

            guy038

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

              @guy038 said in sample config:

              Could it be related to enhancements in Npp v7.9.3 or v7.9.4 releases

              I am getting strange results. The first time I tried in v7.9.2, it didn’t work, and I thought I confirmed that 7.9.2 and 7.9.3 didn’t work. But then I went back to v7.9.2 and tried my new one followed by my old one, and now it seems that the old regex is working in v7.9.2:

              434db432-416e-4555-8c71-a79c6eee86be-image.png

              It’s not truly important. The fixed regex works consistently for me and for you.

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

                @Justin-Lang,

                Sorry, we got into the weeds. In case it’s not clear to you: Don’t use my first regex; there are too many problems with it.

                Instead, use my second, which works more reliably: (?i-s)\A(^(?!username \S+ password \S+).*$\R*)+\z.

                Also, the \A syntax won’t work correctly if you are using a Notepad++ older than v7.9.1, so make sure you have a recent Notepad++. v7.9.1 was the last to have auto-update triggered, so if you’ve checked for updates, you should be on at least v7.9.1. I did confirm that v7.9.1 works with my second regex

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

                  Hi, @peterjones,

                  I did some other tests and there’s definitively something strange with your first regex version. Like you, I got a positive result, just once and some subsequent tests did not find anything !!! Right now, I’m still unable to see the right point and I’m still investigating :-((


                  Now, regarding your second version, sorry, but I’ve found out an issue when a correct line username •••• password •••• begins a line and is followed with some characters, as in the G8.txt file, below :

                  usexrname admin pasxsword cisco
                  username blah password blah 67890
                  some other text
                  

                  With your second regex version (?i-s)\A(^(?!username \S+ password \S+).*$\R*)+\z, the G8.txt file is not listed in the Search results panel, as it should be !

                  If I slightly change your regex as (?i-s)\A(^(?!username \S+ password \S+$).*\R?)+\z, this time, the G8.txt file is correctly part of the list

                  As you can see, I put a $ assertion at the end of the negative look-ahead, deleted this same assertion previously located before \R*, which I also modified as \R? as any line has EOL chars, only once or possibly not in case of the last line of the file !

                  The path is difficult but we will get there !

                  Best Regards

                  guy038

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

                    @guy038 said in sample config:

                    As you can see, I put a $ assertion at the end of the negative look-ahead,

                    Yes, that definitely makes more sense, from the logical/algorithmic standpoint. @Justin-Lang should use that variant if using my “family” of regex at all. Of course, this all assumes that the original assumptions I made, based on just one piece of example text, is sufficient to thoroughly describe the exact rules. The OP has never confirmed whether spaces are allowed before or after, or whether it should match or not match in the weird situations like text before and/or after on the same line, or not. So at this point, I think I’ve done enough for this question from the OP.

                    1 Reply Last reply Reply Quote 0
                    • Justin LangJ
                      Justin Lang @PeterJones
                      last edited by

                      @PeterJones thank you so much for providing well explainnation of the regex. I am learning how to use it to match pattern in the network configuration files. Regex is very interesting and useful to quickly find matches in the file but very confusion too. Thanks for your help. I will continue to rely on your help as I am learning regex if you don’t mind.

                      1 Reply Last reply Reply Quote 0
                      • Justin LangJ
                        Justin Lang @PeterJones
                        last edited by

                        @PeterJones thank you for your advice. I will continue try and learn regex. There is some regex tester online, but each of them support its own flavor of regex. Do you know which regex online tester that support .NET regex ? thanks

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

                          @Justin-Lang ,

                          which regex online tester that support .NET regex ?

                          The Regular Expression FAQ has links to external regex testers. One or more of them may support .NET regex, but I don’t know off the top of my head. Notepad++ uses the Boost regex engine (which is a variant of PCRE), not .NET regex. Since this forum is focused on discussing Notepad++, not supporting and answering questions on all flavors of regex, so if you have .NET regex specific questions, here is not the right place for them.

                          1 Reply Last reply Reply Quote 0
                          • Justin LangJ
                            Justin Lang @guy038
                            last edited by

                            @guy038 thanks so much.

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

                              Hello, @peterjones, @justin-lang, @alan-kilborn and All,

                              To @peterjones only :

                              Let’s back to your first regex version (?i-s)\A(^.*\R(?!^username \S+ password \S+$))+\z. This regex look for a continuous range of lines, not followed with an entire line username •••• password ••••, between the very beginning and the very end of current file. In this case a match occurs and this file is displayed in the Search results window

                              But, if so, in order to match the \z assertion, as the last line of current file may not end with EOL chars, this first version should be (?i-s)\A(^.*\R?(?!^username \S+ password \S+$))+\z with a question mark ? after \R ?

                              And, indeed, this first modified version does work on my machine, with the additional results already known when the username •••• password •••• is the first line of current file

                              Well, end of the story regarding this bugged version, anyway !!


                              To All :

                              I improved my own version to :

                              SEARCH \A(?s)(?:.*?(?i)^username \S+ password \S+$(*SKIP)(*F)|)

                              As you can see :

                              • The regex now uses a non-capturing group ( could be interesting if file of big size or with long lines ! )

                              • It searches for the smallest range of chars till a entire line username •••• password ••••

                              • In case of no line username •••• password •••• exists, in current file, the second empty alternative simply searches the \A position, which is the very beginning location of current scanned file !


                              Now, here is an off-topic subject :

                              When doing all my tests, I wanted to keep the “Find in Files” dialog opened, after each click on the Find All button ! So, I changed, in the <FindHistory •••••••• > section of the config.xml file, the value of the dlgAlwaysVisible attribute from no to yes

                              However, after re-starting N++, no luck : the “Find in Files” dialog was still closed after running a search :-(( I verified that this wrong behavior occurs since the v7.9.0 release !

                              Could you confirm me that fact, with the new Non-XP releases ? In case of positive answer(s), I will create an issue, on GitHub !

                              Best Regards,

                              guy038

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

                                @guy038

                                When doing all my tests, I wanted to keep the “Find in Files” dialog opened, after each click on the Find All button ! So, I changed, in the <FindHistory •••••••• > section of the config.xml file, the value of the dlgAlwaysVisible attribute from no to yes

                                Maybe what you are trying to do manually is conflicting with this setting?:

                                2987c38a-5e94-4097-a8f9-d18f0d69695c-image.png

                                EDIT: I have no idea why my screenshot is twice as big vertically as intended! :-)

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

                                  Hi, @alan-kilborn and All,

                                  How silly am I !! I did not notice that this old setting has been adding in the Preferences dialog. Nice ! So , no need to create any issue : good ;-)) This also explains why this pseudo-issue begins with the v7.9.0 issue !

                                  After ticking this option, in the Preferences dialog and closing N++, the value of the dlgAlwaysVisible attribute is still no in the config.xml file !

                                  Cheers,

                                  guy038

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

                                    @guy038 said in sample config:

                                    After ticking this option, in the Preferences dialog and closing N++, the value of the dlgAlwaysVisible attribute is still no in the config.xml file !

                                    Hmm. I would think that dlgAlwaysVisible would get erased from the FindHistory section at the N++ release that moves control to the Searching section of config.xml; example of that:

                                    <GUIConfig name="Searching" monospacedFontFindDlg="yes" stopFillingFindField="no" findDlgAlwaysVisible="yes" confirmReplaceInAllOpenDocs="yes" />
                                    

                                    Notice the name is now slightly different, too: findDlgAlwaysVisible

                                    But…I really don’t know how such “obsolete” items are handled.

                                    So , no need to create any issue

                                    If obsolete settings are supposed to be removed, maybe THAT’S an issue you could open!

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