Boolean operators in FIND?
-
Is there any way to use a logical OR in “Find”?
-
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.
-
Sweet! Thanks very much. How about the AND operator?
-
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. -
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
andGRACIE
, but you don’t care what order or where in the line, it would be something like(?-s)^(?=.*GEORGE)(?=.*GRACIE).*$
-
Hello, @paul-martinez, @alan-kilborn, @peterjones and All,
Some other hints :
To find all the characters of a
Class_1
which also belong to aClass_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 aClass_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
-
-
@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? -
@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”).