Boolean operators - dnGrep/dnGrep GitHub Wiki

When the Boolean operators search option is checked, you can add Boolean operators between multiple search patterns in the Search for box. This will combine different search patterns into a single operation.

Each search pattern is run separately, and a sub-search will evaluate to TRUE if a match is found, and FALSE if no match is found for that pattern.

Then, the results of each sub-search are logically combined to produce a single result and return all of the matches only if the whole expression evaluates to TRUE.

If two matches from different sub-searches overlap, they will be joined into a single match.

The Boolean expression is evaluated within a scope of one line of a text file, or for the whole file if the Multiline option is selected.

Operators

dnGrep supports the following Boolean operators (which are not case sensitive) in order of precedence:

  • NOT is a unary operator, inverting the value of the following expression.
  • AND is a binary operator returning true if both operands are true.
  • NAND is a binary operator that is equivalent to not (A and B).
  • XOR is a binary operator returning true if either operand is true, but false if both are true.
  • OR is a binary operator returning true if either operand is true.
  • NOR is a binary operator that is equivalent to not (A or B).

Using precedence, combined operators are evaluated this way:

A or B and C		is	A or (B and C)
A and B or C and D	is	(A and B) or (C and D)
A and B and C or D	is	((A and B) and C) or D
not A and B or C	is	((not A) and B) or C

Parentheses are used to alter the order of evaluation:

A or B and C		not equal to	(A or B) and C
A and B or C and D	not equal to	A and (B or C) and D

Note that not A is a valid expression, but A not B is not valid expression. The expression must include a binary operator:
A and not B or A or not B

Quoting the Search Patterns
To include the Boolean operators, parentheses, or white space in the search pattern, the search pattern must be enclosed in back quotes or angle brackets. These two options were chosen for the least interference with regular expression characters (which include all the characters on the keyboard).

`apples and oranges` or bananas
<apples and oranges> or bananas
`apple ` or ` orange`
<apple > and < orange>
`((\"".+?\"")|('.+?'))` and `\d+`
<((\"".+?\"")|('.+?'))> and \d+

Early Exit

The Boolean expression is evaluated after each search pattern is run. If the expression will evaluate to FALSE no matter the outcome of the remaining search patterns, the search will stop and move on to the next line or next file. If, on the other hand, the expression will always evaluate to TRUE, the remaining search patterns will be still run to capture all the remaining matches.

Negative Expressions

With the NOT, NAND and NOR operators, it is possible to make expressions that evaluate to TRUE when no matches are found. In this case, dnGrep will mark the whole line (including empty lines), or whole file if in Multiline mode, as a match.

Replace

If the search type was "Text" you will be able to also use the Replace function.
However, Replace is not enabled for Regex searches with Boolean operators.
Regex Replace is far more complicated with many special cases, and is not suitable for the combined result sets.

 
 

⚠️ **GitHub.com Fallback** ⚠️