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

str contains for strings

Checks if string input contains a substring.

Signature

> str contains {flags} (string) ...rest

Flags

  • --ignore-case, -i: search is case insensitive

Parameters

  • string: The substring to find.
  • ...rest: For a data structure input, check strings at the given cell paths, and replace with result.

Input/output types:

inputoutput
stringbool
tabletable
recordrecord
list<string>list<bool>

Examples

Check if input contains string

> 'my_library.rb' | str contains '.rb'
true

Check if input contains string case insensitive

> 'my_library.rb' | str contains --ignore-case '.RB'
true

Check if input contains string in a record

> { ColA: test, ColB: 100 } | str contains 'e' ColA
╭──────┬──────╮
│ ColA │ true │
│ ColB │ 100  │
╰──────┴──────╯

Check if input contains string in a table

>  [[ColA ColB]; [test 100]] | str contains --ignore-case 'E' ColA
╭───┬──────┬──────╮
│ # │ ColA │ ColB │
├───┼──────┼──────┤
│ 0 │ true │  100 │
╰───┴──────┴──────╯

Check if input contains string in a table

>  [[ColA ColB]; [test hello]] | str contains 'e' ColA ColB
╭───┬──────┬──────╮
│ # │ ColA │ ColB │
├───┼──────┼──────┤
│ 0 │ true │ true │
╰───┴──────┴──────╯

Check if input string contains 'banana'

> 'hello' | str contains 'banana'
false

Check if list contains string

> [one two three] | str contains o
╭───┬───────╮
│ 0 │ true  │
│ 1 │ true  │
│ 2 │ false │
╰───┴───────╯