Community
    • Login

    Boolean operators in FIND?

    Scheduled Pinned Locked Moved General Discussion
    8 Posts 4 Posters 5.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.
    • Paul MartinezP
      Paul Martinez
      last edited by

      Is there any way to use a logical OR in “Find”?

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

        @Paul-Martinez

        Yep. Use Regular expressions. See user manual HERE

        From the “Control Flow” section:

        | ⇒ The alternation operator, which allows matching either of a number of options. For example, one|two|three will match either of one, two or three. Matches are attempted from left to right.

        1 Reply Last reply Reply Quote 1
        • Paul MartinezP
          Paul Martinez
          last edited by

          Sweet! Thanks very much. How about the AND operator?

          Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @Paul Martinez
            last edited by

            @Paul-Martinez

            For “and” you probably have to give some example of what you’re expecting, then we can comment on that specific example.

            The “problem” with “and” is that you’re at a single point in some bit of text and you are processing what comes next. “or” fits nicely there as what comes next could be this or that.

            “and” would be a bit different.
            Certainly doable though, but it might be better if you suggest something you want to do.

            Paul MartinezP 1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @Paul Martinez
              last edited by

              @Paul-Martinez ,

              My initial guess, not knowing what your actual search requirements are: if your AND is order dependent, then just using a normal linear regex would be appropriate; if order doesn’t matter, AND can be accomplished by using two positive lookaheads. For example, if you wanted a line to match only if it had GEORGE and GRACIE, but you don’t care what order or where in the line, it would be something like (?-s)^(?=.*GEORGE)(?=.*GRACIE).*$

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

                Hello, @paul-martinez, @alan-kilborn, @peterjones and All,

                Some other hints :

                To find all the characters of a Class_1 which also belong to a Class_2, use one of the two regex general syntaxes :

                • (?=Class_1)Class_2

                • (?=Class 2)Class_1

                Examples :

                    (?=\d)[[:xdigit:]]          find any HEXADECIMAL character, which is also a DIGIT !         ( Of course, prefer the  [0-9]  regex ! )
                
                    (?-i)(?=[^aeiouy])[a-z]     find any LOWERCASE-letter which is a CONSONANT                  ( idem to the regex  [b-df-hj-np-tv-xz] )
                
                    (?=[\x20-\x7f])\P{alnum}    find any NON-ALPHANUMÉRIC char which is also an ASCII character ( idem to the regex  []\x20!"#$%&'()*+,./:;<=>?@[\\^_`{|}~\x7f-] )
                

                To find all the characters of a Class_1, which do not belong to a Class_2, use the regex syntax :

                • (?!Class_2)Class_1

                Examples :

                    (?-i)(?![[:upper:]])[[:word:]]   find any WORD characters, which is NOT an uppercase letter       ( idem to the regex  [\d\l_] )
                
                    (?-i)(?![aeiouy])[a-z]           find any LOWERCASE-letter which is a CONSONANT                   ( idem to the regex  [b-df-hj-np-tv-xz] )
                
                    (?![[:unicode:]])[[:v:]]         find any VERTICAL BLANK character, which is NOT an UNICODE char  ( idem to the regex  [\n\x0B\f\r\x85]  )
                

                Best Regards,

                guy038

                1 Reply Last reply Reply Quote 0
                • Paul MartinezP
                  Paul Martinez @Alan Kilborn
                  last edited by

                  @Alan-Kilborn @PeterJones @guy038
                  Thanks guys - I have command files for building parts of my database. Currently, the file I go into a lot has about 400 lines in this format: java.(phrase)
                  Sometimes, when I add to the database or do certain tests, I want to pull out a subset so that I don’t have to run the whole thing. Building a subset file of two or more groups of command lines is easy, I just use Find repeatedly, copying the results to another file. This is time consuming, prone to error, and cumbersome when I want three or more groups. The OR (alternation) function as explained by Alan does this handily and I’m very grateful for his rapid assistance.
                  Sometimes it gets more complicated. I might want to Find lines containing CellTypes AND CellStructures, for example, and then Find lines with COVID-19 AND Pathways. (And OR them as this example implies). Peter’s example of George and Gracie looks like it fills the bill, as I don’t care about order or where. For some reason it reminded me of Jack and Diane, although I’ll show my age by pointing out it also reminds me of George Burns and Gracie Allen.
                  Might there be something better, and should I be able to pack this phrase into the alternation structure without breaking anything?

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

                    @Paul-Martinez said in Boolean operators in FIND?:

                    show my age by pointing out it also reminds me of George Burns and Gracie Allen

                    Surely all the young ones reading this are completely lost, but yes, I believe Peter’s example was indeed a reference to the classic duo. :-)

                    In some of my examples here I refer to Bob and Carol and Ted and Alice, which I’m sure likewise makes the youngsters wonder just who are these people?!?

                    Sometimes it gets more complicated

                    It’s really tough to guess at what you want here, although I’m sure some will try that. Again I’d say a really concrete example from you would help speed things along.

                    I might want to Find lines containing CellTypes AND CellStructures, for example, and then Find lines with COVID-19 AND Pathways. (And OR them as this example implies)

                    But is it really an OR that is needed? Or (pun!) is it really just “combining” results from multiple searches?

                    Or is it a cascaded search, meaning from the results of the first AND group, search only those lines for the second AND group?

                    It’s a common problem with postings here, you have to express your need fairly exactly in order to get the best help (i.e., not have someone go off and invest time to solve problem X, only to have someone say “No, no, you fool, I have problem Y, not problem X”).

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