CSV rule for default value if field value is missing/empty

I have just begun using hledger and am just beginning to wrap my head around the deep feature set of the tool. The documentation and examples have also been excellent and I feel like I’ve been able to get pretty far using them.

I have a CSV file where some field values at the end of a record may be missing or empty.

If the value is missing, I would like a rule to substitute in a default value.

In the rules file, I have a field defined as category using the fields directive.

I have tried matching an empty field with "", blank space, or the regex ^$.

How do you match an empty/missing field value?

Thank you.

if
MY_PAYEE
&& %category ""
    account2 Expenses:Default Category

or

if
MY_PAYEE
&& %category ^$
    account2 Expenses:Default Category

Welcome @dempsey. ^$ is the correct way, but are you sure the field is empty - could there be whitespace ?

Another approach is to first set a default value with a fixed assignment, followed by conditional rules which override that.