Complex replacements
The simple replacements like \1
are often not enough. For example, you may want to convert the matching text to lowercase, insert the file name, or add width/height attributes to <img> tags. That's why Aba supports a complex replacement syntax:
Search for | Replace to | Explanation |
</?[a-z]+ |
\(\0.toLower()) |
Convert all HTML tag names to lowercase |
</?[a-z]+ |
\{\0.toLower()} |
Same |
A complex replacement starts with a backslash, then an opening parenthesis, the expression itself, and a closing parenthesis. Instead of the parentheses, you can use braces {} for readability, especially when the expression contains another pair of parentheses.
For the complex replacements, Aba implements a scripting language that is similar to AWK and early JavaScript. This page gives an overview of the syntax and can serve as a quick reference; the next pages describe the supported functions in detail.
Data types
The following data types are supported
- strings in "double" or 'single' quotes;
- double-precision floating-point numbers;
true
orfalse
;null
.
Comparison operators return true
or false
. Strings are automatically converted to numbers and vice versa. For an explicit conversion, use +str
to convert to a number, ('' num)
to convert to a string, and !!something
to convert to a boolean, but this is rarely needed.
An empty string, false
, null
, 0
, and -0
are false values. Everything else is a true value.
Global functions and variables
You can use the same \0
, \1
, etc. syntax inside the \( )
parentheses to refer to the found text and to the subexpressions:
Search for | Replace to | Explanation |
\<(\w+) \1\> |
\(\1) |
Remove repeating words (the the will be changed to a single the ) |
\<(\w+) \1\> |
\1 |
Same, using the simple replacement syntax |
\<(\w+) \1\> |
\(\1.toUpper()) |
Remove repeating words and convert them to uppercase (the the will be changed to THE ) |
\<(\w+) \1\> |
\{\1.toUpper()} |
Same, using braces for readability |
The following global functions are also supported:
- Aba.searchPath() is the directory where you search for the files;
- Aba.filePath() is the relative path of the file where Aba found the match;
- Aba.fileName() is the filename without path;
- Aba.fileNo() is the sequential file number (starting from one);
- Aba.matchNo() is the sequential match number (starting from one and counting across all files);
- Aba.matchNoInFile() is the sequential match number (starting from one and counting in each file separately);
Aba.version()
is the Aba version number.
Operators
The list below shows all operators from highest to lowest precedence:
- parentheses
(expr)
, conditionif cond {value1} else {value2}
, array accessstr[index] str[from:to]
, and member function accessstr.func()
; - unary minus
-num
, unary plus+num
, and unary logical NOT!bool
; - multiplication
num * num
, floating-point divisionnum / num
, integer divisionnum // num
, and remaindernum % num
; - addition
num + num
and subtractionnum - num
; - concatenation
str str
; - comparisons
==
,!=
,<=
,<
,>
, and>=
; - logical AND operator
bool && bool
; - logical OR operator
bool || bool
.
The next pages give more details on the behavior of math operations, concatenation, and logical operators.
The if ... else statement
If the condition is true, the if ... else statement returns the first value, otherwise it returns the default value. Multiple branches are possible:
if cond { value1 } else { defaultValue }
if cond { value1 } else if cond2 { value2 } else { defaultValue }
String functions
The following string functions are supported:
- str.toLower() converts the string to lowercase;
- str.toUpper() converts the string to uppercase;
- str.trimLeft() and
str.trimLeft(charset)
removes spaces or other characters from the beginning of the string; - str.trimRight() and
str.trimRight(charset)
removes spaces or other characters from the end of the string; - str.trim() and
str.trim(charset)
removes spaces or other characters from both sides of the string; - str.indexOf(pattern) returns the first found index of the pattern in the string or −1 if it's not found;
- str.replace(pattern, replacement) and
str.replace(pattern, replacement, count)
replaces the pattern with the replacement; - str.len() returns the string length.
File functions
The following file functions are supported:
- File(fileName).read() reads the whole file and returns its contents;
- File(fileName).meta(propertyName) returns binary file properties such as image height/width, mp3 ID3 tags, etc.
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