Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

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:

inputoutput
anypolars_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 │
╰───┴─────┴─────╯