Skip to content

Removes top-level fields from a record when their names match a regular expression.

drop_matching(x:record, regex:string) -> record

The drop_matching function returns a record with every top-level field from x whose field name does not match regex.

Matching is partial by default. Use ^ and $ anchors to match whole field names or prefixes. The function does not recurse into nested records; call it on the nested record if you want to drop fields there.

The supported regular expression syntax is RE2.

The record whose fields you want to filter.

The regular expression to match against field names.

from {
name: "Alice",
email: "alice@example.com",
password: "secret",
api_key: "xyz123",
}
select public = this.drop_matching("^(password|api_key)$")
{
public: {
name: "Alice",
email: "alice@example.com",
},
}
from {
foo: 1,
bar: 2,
baz: 3,
}
let $pattern = "^ba"
select moved = this.select_matching($pattern),
rest = this.drop_matching($pattern)
{
moved: {
bar: 2,
baz: 3,
},
rest: {
foo: 1,
},
}

Last updated: