# How to use expressions in rules? {#how-to-use-expressions-in-rules}




> [!WARNING]
> **Use of Expressions**
>
> This feature requires 6.1.20 or later and must be manually enabled in 'System Settings - FireFly III Configuration - Enable expression engine' with versions > 6.7.x




## Introduction {#introduction}



Once you've learned [how to use rules](https://sourcey-firefly.pages.dev/how-to/firefly-iii/features/rules/index.md), you may think that rule *actions* are pretty plain. You can update some fields, but it's all pretty static. That's where expressions come in.

Thanks to GitHub user [@michaelhthomas](https://github.com/michaelhthomas) the rule actions now support the Symfony expression engine. This means that you can write a complicate "expression" that result in a new piece of text, or a new value. Depending on the action that you choose, you can do some pretty cool things.



> [!IMPORTANT]
> **Full syntax**
>
> The full syntax of the expression language is documented in the [Symfony documentation](https://symfony.com/doc/current/reference/formats/expression_language.html).



You can read about the fields you can use in the [expression reference](https://sourcey-firefly.pages.dev/references/firefly-iii/rule-expressions/index.md).


## Basics {#basics}


First the basics. A rule action contains a value, and the value will be set in the transaction. Here's an example. It does **not** use the expression engine:

![Basic action](/_media/03380bf4b8b544159581.png)

This rule action will set the category of the transaction to "Groceries". This is pretty straightforward.

An expression starts with `=`. This tells Firefly III that you're about to write an expression. The expression follows.

Here's a simple example that sets the notes of the transaction to whatever the description is.

![Notes action](/_media/9970d2466b45ee3c7a8f.png)

`=description`


## Mathematics {#mathematics}


You can use some simple mathematics, for example on the `amount`-field, to subtract taxes or fees. Here's an action to remove Dutch sales tax from a transaction, which is 21% in most cases:

![Sales tax](/_media/b28887338132c1f19ae8.png)

`=amount-(amount/121)*21`


## Text {#text}


You can join text together using the tilde. This allows you to join two fields together, or add a prefix or suffix to a field. Here is the description added to the notes _twice_.

![Twice](/_media/aa417ab116e2de66e40a.png)

`=description~description`


## Cutting text and text length {#cutting-text-and-text-length}


You can use `strlen` to get the length of a value, and you can use `substr` to cut a part of a value out. You can find a particular piece of text using `strpos`. 

![Strlen](/_media/87b4d4d76d88f68d726e.png)

`=strlen(description)`

This method example cuts of the last four characters of the description:

![Last four](/_media/4dde20cd2cf8d658888e.png)

`=substr(description, 0, -4)`

This allows for more useful combinations. Some of my own transactions always end with the name of the destination account (so it's double). I can cut that off using:

![Last four](/_media/bc9262e7b81a77df8380.png)

`substr(description, 0, strlen(description) - strlen(destination_account_name))`

You can also find a particular piece of text in your description, and remove the rest. For example, if an expense is made through a third party payment provider the destination account name could be "Webshop via Adyen". To fix that, use:

`=substr(destination_account_name, 0, strpos(destination_account_name,'via'))`

You see how `strpos` uses two arguments. The field it searches in, and the text to search for. 


## Other methods {#other-methods}


There are no other methods yet, but they can be added. Are you looking for anything in particular? [Let me know](https://sourcey-firefly.pages.dev/explanation/support/index.md).
