A match mode can change the meaning of "$" to match before any embedded newline (or Unicode line terminator as well). When supported, "\Z" usually matches what the "unmoded" "$" matches, which often means to match at the end of the string, or before a string-ending newline. To complement these, "\z" matches only at the end of the string, period, without regard to any newline. .. //s stands for Single Line Mode which makes the dot match any character. .. //m stands for Multi Line Mode which changes how ^& $ are considered by the regex engine. ^ is then begin of 1 line out of the many lines in the string and not begin of string and $ is end of 1 line out of the many lines in the string and not end of string. .. Caret "^" matches at the beginning of the text being searched, and, if in an enhanced line-anchor match mode after any newline. .. \A always matches only at the start of the text being searched, regardless of single or multi line match mode. .. "\Z" matches what the "unmoded" "$" matches, which means to match at the end of the string, or before a string-ending newline. To complement these, "\z" matches only at the end of the string, period, without regard to any newline.