Home

There is a newer version of this page. You can find it here.

BNFA is C++ regular expression matcher based on non-deterministic finite automata (NFA).

Rules

BNFA uses overloaded operators for writing regular expressions. This syntax was inspired by Boost.Spirit (www.boost.org).

ElementRegular expressionBNFA
OptionalA?-A
One-or-moreA++A
Zero-or-moreA**A
Exactly N timesA{N}A(N)
Between M and N timesA{M,N}A(M,N)
ConcatenationABA >> B
AlternationA | BA | B
Separated listA(BA)*A % B
Positive lookahead(?=A)&A
Negative lookahead(?!A)!A
Characteratext("a")
Any character.any()
Character sequenceabctext("abc")
Character group[abc]group("abc")
Character range[a-z]range('a', 'z')

Examples

  • Match alphabetic letters with [A-Za-z]:

rule alphabetic = range('A', 'Z') | range('a', 'z');

rule digit = range('0', '9');
rule floating = -( group("+-") ) >> ( ( *digit >> text(".") >> +digit ) | +digit );


MongoDB Logo MongoDB