pattern grammar regex replacement

    1

    Replace unreadable regex with maintainable, BNF-style grammar rules for Python validation and parsing.

    Free

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    pattern grammar regex replacement

    Example session with this skill installed

    Create a pattern grammar for a simple ISO 8601 date (YYYY-MM-DD) with custom error messages for each component.

    • Read your context and instructions
    • Compiled the pattern grammar regex

    The grammar below decomposes the ISO 8601 date format into named rules for year, month, and day, each with specific @fail messages for granular error reporting.

    ISO 8601 Date Grammar

    
    # Top-level rule
    date  ::= year "-" month "-" day @fail "Invalid date format, expected YYYY-MM-DD"
    
    # Component rules
    year  ::= [0-9]{4} 
            @fail "Year must be exactly 4 digits"
    
    month ::= "0" [1-9] | "1" [0-2] 
            @fail "Month must be between 01 and 12"
    
    day   ::= "0" [1-9] | [12] [0-9] | "3" [01] 
            @fail "Day must be between 01 and 31"
    

    Next steps

    1. Save this grammar to a file named date_format.pg or load it directly as a string into the Pattern constructor.
    2. Use pattern.match('date', input_string) within a try-except block to catch PatternError and surface the custom messages.
    3. Add a time rule and an optional separator to extend this into a full ISO 8601 datetime validator.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Opaque regular expressions are a liability in production code. They are difficult to read, impossible to unit test in isolation, and fail silently on complex edge cases like nested structures or IPv6 addresses. This skill replaces monolithic regex strings with human-readable, BNF-like pattern grammar rules that are easy to maintain and document.

    What it does

    • Decompose regex by breaking complex expressions into named, logical components.
    • Auto-select engine to use standard regex for flat patterns and Lark LALR parsers for recursive, nested data.
    • Validate formats for common standards including URL (RFC 3986), email, ISO 8601, SemVer, and JSON.
    • Custom error reporting using @fail directives to return specific, actionable messages when a sub-rule fails.
    • Generate test data by producing random strings that conform to your defined grammar rules.
    • Pydantic integration to enforce string formats directly within data models using custom validators.

    How it works

    1. Define rules using ::= syntax to describe each part of your format, from character classes to top-level assembly.
    2. Import grammars from local .pg files or built-in libraries to reuse standard patterns like rfc3986-core.
    3. Initialize patterns in Python to compile the grammar into its most efficient execution form.
    4. Execute checks using match() for Boolean validation or parse() to retrieve a structured AST tree.

    Frameworks & tools

    This tool uses the pattern-grammar Python library, which depends on lark. It optionally integrates with pydantic for schema validation and the regex package for advanced Unicode character class support.

    Why this beats prompting it yourself

    LLMs often hallucinate complex regex lookahead logic or miss subtle RFC requirements. This skill provides a systematic framework for building verifiable grammars that handle recursion and white-space correctly, ensuring the resulting code is actually maintainable by humans.

    Use cases

    • Replace a 40-line URL regex with a structured, multi-line RFC-compliant grammar.
    • Validate nested math or logic expressions that standard regex cannot parse.
    • Build Pydantic models that return specific "Invalid TLD" errors instead of generic failures.
    • Generate synthetic data for testing form validation logic.

    Known limitations

    Does not support lookahead or lookbehind. Rules must be defined via structure or handled in post-parse code. Whitespace is only auto-ignored in recursive rules. Quote escaping is not supported.

    No lookahead/lookbehind support. Whitespace is literal in regex rules. Quote escaping via backslash is unsupported. Recursive depth capped at 100 levels. findall() only works on non-recursive rules.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free forever

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 1 day ago

    • Free with an Agensi account

    Requires

    Python
    Git

    Permissions

    Terminal / Shell
    Read Files
    Network Access
    Listed1 day ago

    What's inside

    Frequently Asked Questions

    This skill replaces monolithic, unreadable regex strings with a structured, BNF-style grammar system that is easier to debug, test, and maintain in Python environments.

    The purchase includes the core logic for translating requirements into grammars, pre-built templates for common RFC standards, and integration patterns for Pydantic and Lark.

    This tool is designed for Python-based environments and integrates seamlessly with the Lark parsing library and Pydantic for data validation.

    Yes, you can use the @fail directive to define custom error messages for specific sub-rules, allowing your application to return actionable feedback like 'Invalid TLD' instead of a generic failure.

    While standard regex handles flat patterns, this skill automatically transitions to LALR parsing to correctly process recursive structures like nested parentheses or JSON-like objects.

    Updates are provided periodically to include new RFC standard templates and optimizations for the latest versions of Pydantic and the pattern-grammar library.

    New in Prompt & Skill Engineering