This won't work because Vim won't scan the same text twice trying to match a different regex.
Even though the
\zs makes the resulting match only include the
bs, Vim needs to see all the
as to be able to match that regex and it won't do so if it already matched the
as to the other pattern.
You can do a small experiment to see this behavior, by doing a simple search for the two regexes:
You'll see that the search will match the
as, but not the
(On the other hand, replacing the
a in the first regex with a different character matches both lines starting with that other character and lines with the
bs following the
as, which proves the regex otherwise works as expected.)
To work around this issue, use a zero-width lookup match, using
\@<= to match the series of
as at the start of the line preceding the
You can use this match instead:
syntax match xB /\(^a\+\)\@<=b\+/
You'll notice this pattern also works correctly in the search experiment:
The reason why this works is that Vim will first search for
bs and then look behind to see if that other part of the regex also matches. So the pattern gets anchored on
b rather than
a and doesn't suffer from the issue of trying to start a match on a region that already matched another expression.
Please note that zero-width lookups such as this one can have performance side effects, if the regex is too generic Vim might end up going pretty far trying to look for the start of a match. See
:help /\@<= for more details.