Skip to main content

Function: between()

Call Signature

between(start, end, str): Option<string>

Defined in: string/extract/index.ts:132

Extracts text between two delimiters.

Returns Some with the extracted text if both delimiters are found, None otherwise.

Parameters

start

string

The starting delimiter

end

string

The ending delimiter

str

string

The string to search

Returns

Option<string>

Option containing the text between delimiters

Example

// Data-first
between('[', ']', 'Hello [world]!')
// => Some('world')

between('$', '.', 'Price: $99.99')
// => Some('99')

between('[', ']', 'No delimiters')
// => None

between('[', ']', '[first] and [second]')
// => Some('first') (only returns first match)

// Data-last (in pipe)
pipe(
'User ID: {12345}',
between('{', '}'),
unwrapOr('unknown')
)
// => '12345'

See

  • words - to split into words
  • lines - to split into lines

Call Signature

between(start, end): (str) => Option<string>

Defined in: string/extract/index.ts:133

Extracts text between two delimiters.

Returns Some with the extracted text if both delimiters are found, None otherwise.

Parameters

start

string

The starting delimiter

end

string

The ending delimiter

Returns

Option containing the text between delimiters

(str): Option<string>

Parameters

str

string

Returns

Option<string>

Example

// Data-first
between('[', ']', 'Hello [world]!')
// => Some('world')

between('$', '.', 'Price: $99.99')
// => Some('99')

between('[', ']', 'No delimiters')
// => None

between('[', ']', '[first] and [second]')
// => Some('first') (only returns first match)

// Data-last (in pipe)
pipe(
'User ID: {12345}',
between('{', '}'),
unwrapOr('unknown')
)
// => '12345'

See

  • words - to split into words
  • lines - to split into lines