Checking conditions
Aba supports logical operators and comparisons that allow you to build complex conditions and choose the replacement based on them.
Logical operators
There are three logical operators:
- A
&&
operator is the logical and. It returns the second operand if the first one can be converted to true. Otherwise, it returns the first operand. In simpler words, it returns a true value if the first and the second operands are true, otherwise it returns a false value. - A
||
operator is the logical or. It returns the first operand if it can be converted to true. Otherwise, it returns the second operand. In simpler words, it returns a true value if the first or the second operands are true, otherwise it returns a false value. - An unary
!
operator is the logical not. It returnstrue
if the operand can be converted to false.
An empty string, false
, null
, 0
, and -0
are false values (can be converted to false
). Everything else is a true value.
Search for | Replace to | Explanation |
(\d{1,2})/(\d{1,2})(?:/(20\d{1,2}))? |
\(\3 || 2023) |
Match a date in the US format; replace it with the year if it's specified, otherwise replace with 2023 |
(\d{1,2})/(\d{1,2})(?:/(20\d{1,2}))? |
\(1 <= \1 && \1 <= 12 && 1 <= \2 && \2 <= 31 && 'valid' || 'invalid') |
Check that the month and the day are valid (between 1 and 31; we don't check the number of days in this month), replace the date with valid or invalid |
Comparison operators
The usual comparison operators are supported:
- equal
x == y
and non-equalx != y
, - less than
x < y
and greater thanx > y
, - less than or equal
<=
and greater than or equal>=
.
Two strings are compared by their Unicode code point order, not linguistically, so you should not rely on the comparison operators for sorting.
When comparing a number to a string, the string is first converted to a numeric value. If it's not possible to convert, the string comparison is used. This allows you to compare the subexpressions (\1
, \2
, etc.) with a number literal if you want a numeric comparison, or with a string literal if you want a string comparison.
Search for | Replace to | Explanation |
anything |
\('25' <
'3') |
A string comparison ('2' < '3', so the result is true) |
anything |
\('25' < 3) |
A numeric comparison (25 > 3, so the result is false) |
The if ... else statement
if cond { value1 } else { defaultValue } if cond { value1 } else if cond2 { value2 } else { defaultValue }
The if ... else
statement consists of a condition and several branches. You can have multiple else if
branches or none of them. The else
statement is mandatory in the replacements; otherwise, Aba would not know what text to use by default. If you need to return an empty string, please write: else {''}
You can also nest if
statements or concatenate results from two or more if
statements. No parentheses are needed around the condition, but the braces are mandatory. In the conditions, you can use the logical operators (&&
, ||
, !
) and comparisons.
Search for | Replace to | Explanation |
20[0-9]{2} |
if \0 == '2024' { 'this year' } else { \0 } |
Replace with this year if the year is 2024 (this can be a part of a more complex replacement, otherwise you can just replace 2024 with this year ) |
20[0-9]{2} |
if \0 == '2024' { 'this year' } else if \0 == '2023' { 'previous year' } else { \0 } |
Also add the previous year for 2023 |
Note that unlike in C, Java, or JavaScript, the if ... else
statement in Aba returns a value, so it's similar to the ternary operator in these languages.
This is a page from Aba Search and Replace help file.
- Welcome to Aba
- Getting started
- How-to guides
- Selecting the files to search in
- Inserting some text at the beginning of each file
- Replacing multiple lines of text
- Searching in Unicode files
- Replacing in binary files
- Performing operations with the found files
- Undoing a replacement
- Saving search parameters for further use
- Removing private data
- Adding or removing Aba from Explorer context menu
- Integrating Aba with Total Commander
- Integrating Aba with Free Commander
- Integrating Aba with Directory Opus
- Regular Expressions
- Replacement syntax
- User interface
- Command line
- Troubleshooting
- Glossary
- Version history
- Credits