polars selector matches for expression
Select all columns that match the given regex pattern.
Signature
> polars selector matches {flags} (pattern)
Parameters
pattern: A valid regular expression pattern, compatible with the rust `regex crate https://docs.rs/regex/latest/regex/
Input/output types:
| input | output |
|---|---|
| any | polars_selector |
Examples
Match column names containing an 'a', preceded by a character that is not 'z'
>
{
"foo": ["x", "y"],
"bar": [123, 456],
"baz": [2.0, 5.5],
"zap": [0, 1],
} |
polars into-df --as-columns |
polars select (polars selector matches "[^z]a") |
polars sort-by bar baz |
polars collect
╭───┬─────┬──────╮
│ # │ bar │ baz │
├───┼─────┼──────┤
│ 0 │ 123 │ 2.00 │
│ 1 │ 456 │ 5.50 │
╰───┴─────┴──────╯Do not match column names ending in 'R' or 'z' (case-insensitively)
>
{
"foo": ["x", "y"],
"bar": [123, 456],
"baz": [2.0, 5.5],
"zap": [0, 1],
} |
polars into-df --as-columns |
polars select (polars selector matches "(?i)R|z$" | polars selector not) |
polars sort-by foo zap |
polars collect
╭───┬─────┬─────╮
│ # │ foo │ zap │
├───┼─────┼─────┤
│ 0 │ x │ 0 │
│ 1 │ y │ 1 │
╰───┴─────┴─────╯