Spec-Zone.ru › Nushell

parse for strings

Parse columns from string data using a simple pattern or a supplied regular expression.

Signature

> parse {flags} (pattern)

Flags

  • --regex, -r: Use full regex syntax for patterns.
  • --backtrack, -b {int}: Set the max backtrack limit for regex.

Parameters

  • pattern: The pattern to match.

Input/output types:

input output
string table
list<any> table

Examples

Parse a string into two named columns.

> "hi there" | parse "{foo} {bar}"
╭───┬─────┬───────╮
│ # │ foo │  bar  │
├───┼─────┼───────┤
│ 0 │ hi  │ there │
╰───┴─────┴───────╯

Parse a string, ignoring a column with _.

> "hello world" | parse "{foo} {_}"
╭───┬───────╮
│ # │  foo  │
├───┼───────┤
│ 0 │ hello │
╰───┴───────╯

This is how the first example is interpreted in the source code.

> "hi there" | parse --regex '(?s)\A(?P<foo>.*?) (?P<bar>.*?)\z'
╭───┬─────┬───────╮
│ # │ foo │  bar  │
├───┼─────┼───────┤
│ 0 │ hi  │ there │
╰───┴─────┴───────╯

Parse a string using fancy-regex named capture group pattern.

> "foo bar." | parse --regex '\s*(?<name>\w+)(?=\.)'
╭───┬──────╮
│ # │ name │
├───┼──────┤
│ 0 │ bar  │
╰───┴──────╯

Parse a string using fancy-regex capture group pattern.

> "foo! bar." | parse --regex '(\w+)(?=\.)|(\w+)(?=!)'
╭───┬──────────┬──────────╮
│ # │ capture0 │ capture1 │
├───┼──────────┼──────────┤
│ 0 │          │ foo      │
│ 1 │ bar      │          │
╰───┴──────────┴──────────╯

Parse a string using fancy-regex look behind pattern.

> " @another(foo bar)   " | parse --regex '\s*(?<=[() ])(@\w+)(\([^)]*\))?\s*'
╭───┬──────────┬───────────╮
│ # │ capture0 │ capture1  │
├───┼──────────┼───────────┤
│ 0 │ @another │ (foo bar) │
╰───┴──────────┴───────────╯

Parse a string using fancy-regex look ahead atomic group pattern.

> "abcd" | parse --regex '^a(bc(?=d)|b)cd$'
╭───┬──────────╮
│ # │ capture0 │
├───┼──────────┤
│ 0 │ b        │
╰───┴──────────╯

Parse a string with a manually set fancy-regex backtrack limit.

> "hi there" | parse --backtrack 1500000 "{foo} {bar}"
╭───┬─────┬───────╮
│ # │ foo │  bar  │
├───┼─────┼───────┤
│ 0 │ hi  │ there │
╰───┴─────┴───────╯

Notes

The parse command always uses regular expressions even when you use a simple pattern. If a simple pattern is supplied, parse will transform that pattern into a regular expression.

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/parse.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API