# What Operators Are Supported by Probe's Expression Engine? Complete Syntax Reference

> Discover the operators supported by Probe's expression engine. Explore arithmetic, comparison, logical, and custom functions like random_int() for flexible data manipulation.

- Repository: [Tomohisa Oda/probe](https://github.com/linyows/probe)
- Tags: api-reference
- Published: 2026-03-06

---

**Probe's expression engine supports arithmetic, comparison, logical, ternary, and null‑coalescing operators inherited from the expr‑lang/expr library, alongside custom functions like `random_int()` and `match_json()`.**

Probe is a lightweight workflow automation tool that evaluates dynamic expressions through a sandboxed engine. The system delegates expression parsing to the proven expr‑lang/expr library while layering additional safety controls and domain-specific functions on top. Understanding which operators are available helps you write precise conditional logic and variable transformations in your workflow definitions.

## Arithmetic and Comparison Operators

Probe inherits standard mathematical and equality operators from the underlying expr library. These work on numeric types and strings where applicable.

**Arithmetic operators** include:

- `+` for addition
- `-` for subtraction
- `*` for multiplication
- `/` for division
- `%` for modulo

**Comparison operators** include:

- `==` for equality
- `!=` for not equal
- `<` for less than
- `<=` for less or equal
- `>` for greater than
- `>=` for greater or equal

In [`expr_test.go`](https://github.com/linyows/probe/blob/main/expr_test.go), the `TestEvalOrEvalTemplate` function demonstrates basic arithmetic: `{{ 1 + 1 }}` evaluates to `2`. For HTTP status checks, you might use `{{ status >= 200 && status < 300 }}` as shown in `TestEval`.

## Logical and Conditional Operators

Beyond basic math, Probe supports boolean logic and conditional evaluation.

**Logical operators**:

- `&&` for logical AND
- `||` for logical OR
- `!` for logical NOT

**Conditional operators**:

- **Ternary**: `condition ? trueVal : falseVal` for inline if‑else logic
- **Null‑coalescing**: `??` for providing default values when the left side is nil or empty

The test suite in [`expr_test.go`](https://github.com/linyows/probe/blob/main/expr_test.go) validates these through `TestEval` and `TestEvalTemplate`. For example, `{{ res.code == 200 && res.body.success }}` combines comparison with logical AND, while `{{ env.URL == 'localhost' ? 'http://localhost:3000' : env.URL }}` demonstrates ternary selection.

## Domain‑Specific Functions

Probe extends the base engine with custom functions defined in [`funcs.go`](https://github.com/linyows/probe/blob/main/funcs.go). These are registered in [`expr.go`](https://github.com/linyows/probe/blob/main/expr.go) and available alongside standard operators.

**Utility functions**:

- `random_int(max)` – Returns random integer from 0 to max‑1
- `random_str(len)` – Generates random string of specified length
- `unixtime()` – Returns current Unix timestamp

**Data processing**:

- `match_json(src, tgt)` – Compares two JSON structures
- `diff_json(src, tgt)` – Returns differences between JSON structures
- `encode_base64(str)` and `decode_base64(str)` – Base64 transformations
- `parse_int(val)` and `parse_float(val)` – Type conversions

These functions are tested in `TestNewCustomFunctions` and `TestCustomFunctions` within [`expr_test.go`](https://github.com/linyows/probe/blob/main/expr_test.go).

## Security Architecture and Limitations

The engine deliberately restricts functionality to maintain sandbox safety. According to the implementation in [`expr.go`](https://github.com/linyows/probe/blob/main/expr.go), Probe disables all built‑in functions via `ex.DisableBuiltin("all")` and re‑enables only the whitelisted custom functions listed above.

Safety mechanisms include:

- **Expression length limit**: 1,000,000 characters (`maxExpressionLength`)
- **Evaluation timeout**: 5 seconds default (`evaluationTimeout`)
- **Environment filtering**: The `createSafeEnvironment` function blocks dangerous keys like `SECRET` and `PATH` through the `isSafeEnvKey` helper

These safeguards are exercised in `TestSecurityValidation` and `TestSafeEnvironment` in the test suite.

## Practical Usage Examples

When writing Probe workflows, you can combine operators and functions in templates or direct evaluations.

Arithmetic with variables:

```go
env := map[string]any{"count": 10}
result, _ := expr.Eval("count * 2 + 5", env) // → 25

```

Conditional routing:

```go
env := map[string]any{"status": 404}
isNotFound, _ := expr.Eval("status == 404", env) // → true

```

Template with null‑coalescing:

```go
env := map[string]any{"env": map[string]any{"API_URL": nil}}
url, _ := expr.EvalTemplate("{{ env.API_URL ?? 'http://localhost:8080' }}", env)
// → "http://localhost:8080"

```

Combining functions and operators:

```go
// Generate random delay between 0-9 seconds
delay, _ := expr.Eval("random_int(10) * 1000", nil)

```

## Summary

- Probe delegates expression evaluation to the **expr‑lang/expr** library, supporting arithmetic (`+`, `-`, `*`, `/`, `%`), comparison (`==`, `!=`, `<`, `<=`, `>`, `>=`), and logical (`&&`, `||`, `!`) operators.
- **Ternary** (`? :`) and **null‑coalescing** (`??`) operators enable conditional logic and safe fallback values.
- Nine **custom functions** including `random_int()`, `match_json()`, and `encode_base64()` extend the base operator set for workflow-specific tasks.
- Security controls in [`expr.go`](https://github.com/linyows/probe/blob/main/expr.go) limit expression length, execution time, and environment access while disabling all non‑whitelisted built‑ins.

## Frequently Asked Questions

### Can I use regular expressions in Probe expressions?

No, the expr‑lang/expr library used by Probe does not expose regular expression operators in its default grammar. For pattern matching, use the `match_json()` function to compare structures or preprocess values in your workflow steps before evaluation.

### What happens if an expression evaluates for longer than 5 seconds?

Probe forcibly terminates the evaluation and returns an error. The `evaluationTimeout` constant in [`expr.go`](https://github.com/linyows/probe/blob/main/expr.go) sets a hard limit of 5 seconds to prevent runaway computations from blocking workflow execution.

### Are there any operator precedence rules I should follow?

Yes, standard mathematical precedence applies: multiplication and division evaluate before addition and subtraction, and comparison operators evaluate after arithmetic. Parentheses can override precedence. Logical operators follow the conventional order where `!` binds tightest, then `&&`, then `||`.

### Why can't I access environment variables like PATH or SECRET in expressions?

Probe filters environment access through the `isSafeEnvKey` function in [`expr.go`](https://github.com/linyows/probe/blob/main/expr.go) to prevent information leakage. Keys containing sensitive patterns like `SECRET`, `PATH`, or `TOKEN` are blocked by `createSafeEnvironment` before evaluation begins.