parse for strings

Parse columns from string data using a simple pattern.

Signature

> parse {flags} (pattern)

Flags

  • --regex, -r: use full regex syntax for patterns

Parameters

  • pattern: The pattern to match.

Input/output types:

inputoutput
list<any>table
stringtable

Examples

Parse a string into two named columns

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

Parse a string using regex pattern

> "hi there" | parse --regex '(?P<foo>\w+) (?P<bar>\w+)'
╭───┬─────┬───────╮
 # │ 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        
╰───┴──────────╯