(?<=pattern) and (?=pattern) are called assertions. Assertions are different than the classic items like ., [chars] etc in the way that they do not "consume" any characters. To see what I mean, first try this:
//echo -a $regex(abcd,/[a-z](.+)/) - $regml(1)
the output is "1 - bcd". What happened here is that [a-z] matches the letter "a" and consumed it: the rest of the pattern will start matching AFTER the letter "a", because "a" is no longer available to participate in the matching process. It has been consumed by [a-z].

Now try this:
//echo -a $regex(abcd,/(?=[a-z])(.+)/) - $regml(1)
output is now "1 - abcd". That's because (?=[a-z]) did match "a" but did not consume it: it just took a peek at the letter ahead ("a") and made sure that it matches [a-z], hence its name "lookahead assertion". It's a sort of pre-check, to decide if the normal, consuming items can carry on and eat characters. So (.+) starts from "a" (and not from "b", like in the previous example). (?<=[a-z]) is similar, except that it takes a peek behind the current position and is called "lookbehind assertion".

In our case of $text, /(?<= |^)(?= |$)/g matches the position in the string that has a space behind it (or start-of-string) and another space ahead of it (or end-of-string). $regsub() then inserts a ^B pair in that position. Note that using /( |^)( |$)/g wouldn't work correctly. The position between the two spaces would also be found, but the space that's ahead has been consumed, so at the next /g-induced matching round it will no longer play the role of a space behind the current position for ( |^) to find. This means that the expression would fail with 3 consecutive spaces.

It's not easy at all to describe assertions in such a way that their usefulness becomes apparent to the reader. One of the most explanatory docs I've seen on this subject is this, so you may want to take a look at it.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com