# 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/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/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/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()` rewrite rule. 

## Declaration
```
    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:
```
 
    rewrite {
        set-matches("foo,bar,baz");
    };
    
```

Using a list template function:
```
 
    rewrite {
        set-matches("$(explode ':' 'foo:bar:baz')");
    };
    
```

Last modified April 9, 2025: [Rewrite-related formatting fixes and title shortenings (07c928a3)](<https://github.com/axoflow/axosyslog-core-docs/commit/07c928a36247e7d98c8d00726187c3afdbc96875>)