W3cubDocs

/Nushell

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
  • --not, -n: does not contain

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:

input output
list<string> list<bool>
record record
string bool
table table

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-i'.RB'
true

Check if input contains string in a record

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

Check if input contains string in a table

>  [[ColAColB]; [test100]] |str contains-i'E'ColA
╭───┬──────┬──────╮
# │ ColA │ ColB │
├───┼──────┼──────┤
0true100
╰───┴──────┴──────╯

Check if input contains string in a table

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

Check if input string contains 'banana'

>'hello'|str contains'banana'
false

Check if list contains string

> [onetwothree] |str containso
╭───┬───────╮
0true
1true
2false
╰───┴───────╯

Check if list does not contain string

> [onetwothree] |str contains-no
╭───┬───────╮
0false
1false
2true
╰───┴───────╯

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