[ Prev ] [ Index ] [ Next ]

String Functions

Created Saturday 15 August 2020

s = substring to match wihtin string
r = replacement string
p = position
l = length

${#string} Length of $string
${string:p} Extract s from $string at $p
${string:p:l} Extract $l characters s from $string at $p [zero-indexed, first character is at position 0]
${string#s} Strip shortest match of $s from front of $string
${string##s} Strip longest match of $s from front of $string
${string%s} Strip shortest match of $s from back of $string
${string%%s} Strip longest match of $s from back of $string
${string/s/r} Replace first match of $s with $r
${string//s/r} Replace all matches of $s with $r
${string/#s/r} If $s matches front end of $string, substitute $r for $s
${string/%s/r} If $s matches back end of $string, substitute $r for $s