🔡 Splits a string into an array of its words.
Syntax
TypeScript
import { words } from '@opentf/std'; words( str: string, pattern?: RegExp | string ): string[];
Parameters
str: The string to split.pattern(Optional): The pattern to use for splitting.
Returns
An array of words.
String patterns are treated literally. Use a RegExp when you need regex matching behavior.
Examples
TypeScript
words('fred, barney, & pebbles') //=> ['fred', 'barney', 'pebbles'] words('fred, barney, & pebbles', /[^, ]+/g) //=> ['fred', 'barney', '&', 'pebbles'] words('a+b+c', '+') //=> ['+', '+']