{
  "slug": "regex-literal-escape",
  "name": "gizza-ai/regex-literal-escape",
  "version": "0.1.0",
  "title": "Regex Escape — Turn Text Into a Regex-Safe Literal (PCRE, JS, RE2) — gizza.ai",
  "description": "Escape special characters so a regex matches text literally. Nine flavors: PCRE, JavaScript, Python, Go/RE2, .NET, Java, Ruby, and Rust.",
  "tags": [
    "regex escape",
    "escape regex characters",
    "preg_quote",
    "RegExp.escape",
    "re.escape",
    "QuoteMeta",
    "Regex.Escape",
    "Pattern.quote",
    "regex special characters",
    "escape metacharacters"
  ],
  "category": "developer",
  "urls": {
    "page": "https://gizza.ai/tools/regex-literal-escape/",
    "markdown": "https://gizza.ai/tools/regex-literal-escape/index.md",
    "descriptor": "https://gizza.ai/tools/regex-literal-escape/tool.json",
    "deep_link_example": "https://gizza.ai/tools/regex-literal-escape/?text=a.b%2Ac%2B%28d%29&flavor=pcre&delimiter=%2F&escape_whitespace=true&string_literal=true"
  },
  "cli": "gizza tool regex-literal-escape \"a.b*c+(d)\"",
  "tool": {
    "description": "Escape arbitrary text so a regex engine matches it literally, using the exact rules of the flavor you pick. flavor=pcre (PHP preg_quote, default), javascript (the escapeRegExp idiom), javascript-strict (ES2025 RegExp.escape), python (re.escape), re2 (Go regexp.QuoteMeta), dotnet (.NET Regex.Escape), java (Pattern.quote, \\Q…\\E), ruby (Regexp.escape), or rust (regex::escape) — the metacharacter sets differ, e.g. Go leaves '-' and '#' alone while PCRE escapes them. Set delimiter='/' to also escape your pattern delimiter, escape_whitespace=true for portable \\t/\\n/\\x20 escapes (needed in /x extended mode), and string_literal=true to double backslashes for pasting inside a source-code string. Returns the escaped literal. Runs locally.",
    "parameters": {
      "additionalProperties": false,
      "properties": {
        "delimiter": {
          "default": "",
          "description": "Extra punctuation characters to escape as well, like the second argument of preg_quote — usually your pattern delimiter, e.g. '/' or '#'. Letters, digits, underscores, and whitespace are rejected. Default: none.",
          "type": "string"
        },
        "escape_whitespace": {
          "default": false,
          "description": "Emit portable escapes for whitespace (\\t \\n \\r \\f \\v and \\x20 for a space) instead of the flavor's native handling. Turn this on for PCRE/Ruby extended (/x) mode, where a raw space is ignored. Default: false.",
          "type": "boolean"
        },
        "flavor": {
          "default": "pcre",
          "description": "Which engine's escaping rules to reproduce: 'pcre' (PHP preg_quote, default), 'javascript' (the escapeRegExp idiom for new RegExp), 'javascript-strict' (ES2025 RegExp.escape, hex-escapes the first letter/digit), 'python' (re.escape), 're2' (Go regexp.QuoteMeta), 'dotnet' (.NET Regex.Escape), 'java' (Pattern.quote, wraps in \\Q…\\E), 'ruby' (Regexp.escape), or 'rust' (regex::escape). The metacharacter sets really do differ.",
          "enum": [
            "pcre",
            "javascript",
            "javascript-strict",
            "python",
            "re2",
            "dotnet",
            "java",
            "ruby",
            "rust"
          ],
          "type": "string"
        },
        "string_literal": {
          "default": false,
          "description": "Also escape the result for pasting between the quotes of a source-code string literal: backslashes are doubled and double quotes escaped. Use for Java/C#/Go/JS string literals, not for raw strings. Default: false.",
          "type": "boolean"
        },
        "text": {
          "description": "The literal text to escape, e.g. 'a.b*c+(d)'. Up to 100000 characters.",
          "type": "string"
        }
      },
      "required": [
        "text"
      ],
      "type": "object"
    }
  }
}