Assetions are non-consuming matchers.
BNFA rules are anchored at the start and end of the input by default, and BNFA does therefore not provide anchors to match against the start of the line (^) and the end of the line ($). If you wish to have unanchored matching, then you need to match zero-or-more any characters at the beginning and the end of the expression.
| Regular expression | BNFA |
|---|---|
| ^A$ | A |
| ^A | A >> *any() |
| A$ | *any() >> A |
| A | *any() >> A >> *any() |
Positive and negative lookahead assertions checks that the input matches a pattern without consuming input. A positive lookahead assertion is marked by an ampersand (&) followed by a rule. A negative lookahead assertion is marked by an exclamation mark (!) followed by a rule.
| Regular expression | BNFA |
|---|---|
| A(?=B) | A >> &(B >> *any()) |
| A(?!B) | A >> !(B >> *any()) |
Notice that the lookahead assertion rule is anchored at the start and end of the line (strictly speaking, it is not anchored at the start of the line, but rather immediately after the input consumed so far) just like any other rule, so we have to rewrite it as B >> *any() to get the usual regexp behavior.