Search

Dark theme | Light theme

September 2, 2026

Nushell Niceties: Split String By Words

To split a string value by the words in the string you can use the command split words. The result is a list where each element is a word from the original string. You can use the option --min-word-length (or the short option -l) to specify a minimal length of the words that should be split on. When a word length is less than the given option value it will not be in the resulting list.

In the following example the split words command is used:

use std/assert

# Using split words command to split words from a string
# into an array of words.
assert equal ('Nushell rocks' | split words) ['Nushell' 'rocks']
assert length ('Working with data' | split words) 3

# Using the option --min-word-length (or short -l) to specify
# the minimal length words should have to split.
assert equal ('Nushell is awesome' | split words --min-word-length 3) ['Nushell' 'awesome']
assert length ('Working with data' | split words -l 5) 1

Written with Nushell 0.115.1.