extractBetween

Extracts the text between two markers or two positions.

Category: Language Fundamentals > Data Types

Syntax

newStr = extractBetween(str, startPat, endPat)

Returns what lies between startPat and the next endPat.

newStr = extractBetween(str, startPos, endPos)

Returns the characters from startPos to endPos.

newStr = extractBetween(___, 'Boundaries', 'inclusive')

Keeps the markers in the result.

Description

This is the usual way to pull a field out of text such as "name [id] value". Each start marker is paired with the next end marker, and every such pair yields one piece.

Input arguments

startPat, endPat
Marker text or pattern objects.
startPos, endPos
Positive integers: first and last character to return.
'Boundaries'
'exclusive' (default) drops the markers; 'inclusive' keeps them.

Output arguments

newStr
String array of the extracted pieces.

Example

Between brackets

extractBetween("a[bc]d", "[", "]")
extractBetween("a[bc]d", "[", "]", "Boundaries", "inclusive")
Output
ans = "bc"
ans = "bc"

See also

extractAfter extractBefore extract eraseBetween regexp