Doing math

You can do math operations with the found match \0 or with the subexpressions (\1, \2, etc.) For example:

Search forReplace toExplanation
202[0-9] \(\0+1) Increment the found year by one (2023 will be changed to 2024)

String values are implicitly converted to numbers. A string used in math operations must be numeric, otherwise Aba shows an error message. For example, "5N" + 1 won't work.


The following counters are supported:

All counters start from 1, but you can add some math operations to start counting from any other number or count even/odd numbers only. Examples:

Search forReplace toExplanation
^ \{Aba.matchNoInFile() " "} Add a line number to each line
^\N? \(if \0 {Aba.matchNoInFile() " " \0} else {\0}) Add line numbers to non-empty lines only
<img <img id="x\{Aba.matchNo() - 1}" Add an unique id starting from zero to each <img> tag
<img <img id="x\{Aba.matchNo() * 2 - 1}" Same, start from one and use odd numbers only (1, 3, 5, etc.)

Number literals

You can use double-precision floating-point numbers like 3.14159_26535, 6.02214076e23, or 1.380649e-23.

This includes integer numbers from -9007199254740991 to 9007199254740991 (2⁵³ − 1), which is enough to represent the whole 32-bit integer range, but not enough for 64-bit integers. If an integer value is outside of this range, Aba shows an error message. You can operate with the larger numbers, but the operations will be inexact and you need to write them in the format with mantissa and exponent: 9.00719925474100e15.

An underscore can be used anywhere between two digits, for example, to separate thousands: 9_007_199_254_740_991.

An uppercase or lowercase letter E is used for the exponent: 6.02214076E23 or 6.02214076e+023 are the same and mean 6.02214076 × 10²³.

Math operations

Aba supports the four basic arithmetic operations: + - / *. Double-precision floating-point arithmetic is used internally, so the result is inexact just like in other programming languages.

The //operator is an integer division,% is a floating-point remainder (modulo operator). Note that Aba rounds towards zero (truncates the result) similarly to dividing integer numbers in C, JavaScript, or Java, while Python rounds towards negative infinity (does a floor division). Same for the remainder operation: Aba's implementation is the same as the fmod function in C or the % operator in JavaScript and Java. For negative numbers, the result is different from Python; for positive numbers, it's the same.

Search forReplace toExplanation
anything \(-7 // 2) Truncating division; the result (the quotient) is −3
anything \(-7 % 2) The remainder is −1, so that quotient × divisor + remainder = dividend = −3 × 2 - 1 = −7
anything \(3.5 // 2) The quotient is 1
anything \(3.5 % 2) The remainder is 1.5, so that 2 × 1 + 1.5 = 3.5

Division by zero shows an error message.

This is a page from Aba Search and Replace help file.