Super Expressive
Super Expressive

Super Expressive is a JavaScript library that allows you to build regular expressions in almost natural language - with no extra dependencies, and a lightweight code footprint (less than 3kb with minification + gzip!).

Super Expressive is a JavaScript library for building regular expressions in (almost) natural language.

Features:

  • Natural Language Approach: Super Expressive allows developers to create regular expressions using a more human-readable and programmatic way, rather than cryptic syntax. The library's API uses a fluent builder pattern and is completely immutable.

  • Readability and Maintainability: The library is designed to produce regular expressions that are easier to read, understand, and maintain. The properties and methods describe what they do in plain English, and the order of operations mirrors that of the English language.

  • Error Guidance: Super Expressive guides users toward fixes if their expressions are invalid.

  • Code Footprint: The library has a small code footprint of less than 4kb with minification and gzip. It also has no extra dependencies.

  • Reusability: Subexpressions can be used to create meaningful, reusable components.

  • TypeScript Support: Super Expressive includes an index.d.ts file for full TypeScript support.

  • API: The API is extensive and includes methods to match various types of characters and patterns. Some notable methods include:

    • Flags: .allowMultipleMatches, .lineByLine, .caseInsensitive, .generateIndices, .sticky, .unicode, and .singleLine which use the g, m, i, d, y, u, and s flags, respectively.

    • Character Matching: .anyChar, .whitespaceChar, .nonWhitespaceChar, .digit, .nonDigit, .word, .nonWord.

    • Boundaries: .wordBoundary, and .nonWordBoundary.

    • Specific Characters: .newline, .carriageReturn, .tab, .verticalTab, .formFeed, .backspace, and .nullByte.

    • Grouping and Capturing: .anyOf, .capture, .namedCapture(name), .backreference(index), .namedBackreference(index), .group, and .end().

    • Assertions: .assertAhead, .assertNotAhead, .assertBehind, and .assertNotBehind.

    • Quantifiers: .optional, .zeroOrMore, .zeroOrMoreLazy, .oneOrMore, .oneOrMoreLazy, .exactly(n), .atLeast(n), .atLeastLazy(n), .between(x, y), and .betweenLazy(x, y).

    • Anchors: .startOfInput and .endOfInput.

    • Character Sets: .anyOfChars(chars), .anythingBut, .anythingButChars(chars), .anythingButString(str), .anythingButRange(a, b), and .range(a, b).

    • Strings and Characters: .string(s), .char(c), .controlChar(c), .hexCode(hex), .utf16Code(hex), and .unicodeCharCode(hex).

    • Unicode Properties: .unicodeProperty(property) and .notUnicodeProperty(property).

    • Subexpressions: .subexpression(expr, opts) which allows for the inclusion of other Super Expressive instances.

    • Output Methods: .toRegexString() and .toRegex() which output a string representation of the regular expression and a regular expression, respectively.

  • Playground: The Super Expressive Playground by @nartc allows users to experiment with the library and test their regexes.

  • Ports: Super Expressive has been ported to other languages including PHP, Ruby and Python.

In summary, Super Expressive aims to make the creation and maintenance of regular expressions more approachable and understandable by providing a fluent, programmatic API that closely mirrors natural language, while also offering a wide range of functionalities.