headerphoto

apg-exp–APG Expressions

apg-exp is a new regex-like pattern-matching engine that uses the SABNF syntax for the pattern definitions and APG to create and apply the pattern-matching parser. It has been designed to have the look and feel of JavaScript RegExp. However, it has a much richer feature set and is a more powerful pattern matching engine.

Because of the SABNF syntax, the matching of nested pairs, (()), {{}}. etc., is natural and complete in apg-exp Nested pair matching is not supported in JavaScript RegExp

apg-exp also uniquely features two modes of back referencing. "Universal mode" is the equivalent of standard regex back referencing.1 However, a new "parent mode" has been introduced here. Among other things, it can be used with recursion (nested pairs) to match named, opening and closing HTML tags. An example of this can be found here.

Other features of APG greatly enhance the power of apg-exp. Especially check out,

  • UDTs for hand-written code to match that special, difficult phrase.
  • Abstract Syntax Tree (AST) for complex translations of the matched phrases.
  • The APG trace for pattern syntax debugging.
  • Many more features. See the README file and the complete user's guide.

Don't miss the tutorial on sitepoint.com. It will walk you through the basics from simple to some fairly sophisticated pattern matching of nested, paired parentheses and other brackets. It's all laid out for you with nine (9), hands-on, CodePen examples.