Instructor
If:
\A - matches the position at the beginning of the search range,
\Z - matches the position at the end of the search range,
in the previous test version it worked well.

In the new test version it is inconsistent.
In the above example, regexp matches 9 times (8 times "b" and 1 time new line), and replaces only 2 times.

I propose to add two new anchors \a, \z (or change the way of working \A, \Z), so that:
\a - matches the position at the start of the text,
\z - matches the position at the end of the text.
"\a" should match only the beginning of the text (only once), like "^" matches only the beginning of the line (only once, if there is one line).

\A Matches the position at the beginning of the document...
\Z Matches the position at the end of the document...
\a Same as \A, but matches the position at the beginning of the search range.
\z Same as \Z, but matches the position at the end of the search range.

\A Matches the position at the beginning of the document...
\Z Matches the position at the end of the document...
\a Same as \A, but matches the position at the beginning of the search range.
\z Same as \Z, but matches the position at the end of the search range.