# Set match variables

Match macros (`$1, $2, ... $255`) are temporary variables. You can use them for general purposes when operating with list-like items. For example, the [match() filter](../../../docs/axosyslog-core/4.26/chapter-manipulating-messages/regular-expressions/index.md) stores capture group results in match variables when the `store-matches` flag is set, or the [JSON parser](../../../docs/axosyslog-core/4.26/chapter-parsers/json-parser/index.md) produces match variables if the parsed JSON data is an array.

It is possible to set match variables in a single operation with the `set-matches()` rewrite function. `set-matches()` uses AxoSyslog list expressions to set `$1, $2, ... $255`, so it can be considered as a conversion function between AxoSyslog lists and match variables.

Note To convert match variables into a AxoSyslog list, use the `$*` macro, which can be further manipulated using [list template functions](../../../docs/axosyslog-core/4.26/chapter-manipulating-messages/customizing-message-format/reference-template-functions/index.md), or turned into a list in type-aware destinations. 

Note To reset match variables to be empty, use the [`unset-matches()`](../../../docs/axosyslog-core/4.26/chapter-manipulating-messages/modifying-messages/rewrite-set-matches/index.md#unset-matches) rewrite rule. 

## Declaration

Terminal window
```
    rewrite <name_of_the_rule> {
        set-matches("<list-expression or list-based template function>");
    };
```

## Example for the set-matches() rewrite function

In the following two examples, `$1`, `$2`, and `$3` will be set to `foo`, `bar`, and `baz`, respectively.

Using strings:

Terminal window
```
    rewrite {
        set-matches("foo,bar,baz");
    };
```

Using a list template function:

Terminal window
```
    rewrite {
        set-matches("$(explode ':' 'foo:bar:baz')");
    };
```

## unset-matches()

The `unset-matches()` rewrite rule clears every match variable, that is, it resets `$1, $2, ... $255` to empty. Use it when you want to make sure that match variables left over from an earlier filter, parser, or rewrite rule do not leak into later parts of the log path.

Terminal window
```
    rewrite <name_of_the_rule> {
        unset-matches();
    };
```

### Example for the unset-matches() rewrite function

The following log path sets three match variables, then clears them again, so `$1`, `$2`, and `$3` are empty when the message reaches the destination.

Terminal window
```
    log {
        source(s_local);
        rewrite { set-matches("foo,bar,baz"); };
        rewrite { unset-matches(); };
        destination(d_local);
    };
```

## Options

Both `set-matches()` and `unset-matches()` have the following option.

## condition()

|   
---|---  
Type: | filter expression  
Default: | N/A  
  
_Description:_ Applies the rewrite rule only to the messages that match the specified filter expression. Messages that don’t match the filter pass through the rule unmodified, and continue to the next element of the log path. You can use any filter expression here, and you can reference an existing filter with the `filter()` function. For details, see [Conditional rewrites](../../../docs/axosyslog-core/4.26/chapter-manipulating-messages/modifying-messages/conditional-rewrite/index.md).

Last modified August 10, 2026: [Sync rewrite rule options with the source (d33662b7)](<https://github.com/axoflow/axosyslog-core-docs/commit/d33662b7e6212a930666d724aa0ba2f88d4ba4ae>)