replaceBetween

Replaces the text found between two markers.

Category: Language Fundamentals > Data Types

Syntax

newStr = replaceBetween(str, start, stop, new)

Replaces what lies between start and stop by new, keeping the markers.

newStr = replaceBetween(___, 'Boundaries', b)

b is 'exclusive' (default) or 'inclusive'.

Description

The markers are located by searching from the left: first start, then the next stop after it. By default the markers are not part of the replaced region, which suits changing the content inside brackets or tags.

Input arguments

str
Text to search.
start, stop
Boundary text or patterns, or numeric positions.
new
Replacement text.

Output arguments

newStr
Text with the content between the boundaries replaced.

Example

replaceBetween("abc[def]ghi", "[", "]", "XY")
Output
ans = "abc[XY]ghi"

See also

extractBetween insertBefore replace extractAfter eraseBetween