If \b, a zero-width assertion, doesn't care whether it's placed before or after the word it's guarding (so to speak), why should (?= ) care that it is for lookahead only? What is it that makes (?<= ) necessary, and (?= ) unable to fill both niches?
Then the concept comes to mind of the ^ and $ anchors. They're zero-width, and unlike \b, they care about which one gets used, and where. But maybe through habbit, that idiom seems to make sense and lend clarity. In other regexp flavors we see things like \< and \> to represent \b in a more placement-sensitive way. Perl seems fine with the simple \b. Wouldn't Perl be "just fine" with (?= ) filling the roll as both a zero width lookahead and a zero width lookbehind?
Then there's the other question.... why does (?<= ) have to contain fixed-length matches (ie, no quantifiers like + or *, and no lopsided alternation), while (?= ) is allowed to contain quantifiers or lopsided alternations (in other words, doesn't have to be fixed length)?
I've dug into Camel II, Owls, perlre, and perlretut but haven't found the answer. Perhaps the answer is just "that's the way it is." Is it? ;)
Dave
In reply to Why do zero width assertions care about lookahead/behind? by davido
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |