replace

Find occurrences of a pattern and replace them with a string.

Usage

z replace <pattern> <replace-string> <occurrence-range>

Arguments

pattern Mandatory. The regular expression pattern to be matched.
Type: pattern.
replace-string Mandatory. The string that will replace the matches.
Type: string.
occurrence-range Optional. The half-open match index range where replacement will occur. negative range end means counting in reverse order. zero range end means last match.
Type: range.
Default value: "0:0".

Examples

# replacing ":" by "\n"
z replace : "\n"

# removing all ":"
z replace : ""

# replacing all alphabetical characters with "0"
z replace [A-z] 0

# replacing all but first "0" with "zero"
z replace 0 "zero" 1:

# replacing all but first and last "1" with "one"
z replace 1 "one" 1:-1

# removing the first "."
z replace . "" 0:1