{"id":"regex-check","title":"Regex catastrophic-backtracking check, then test cases only if proven safe","description":"Statically analyses an ECMAScript regular expression (up to 500 characters) for catastrophic backtracking (nested or overlapping quantifiers, ambiguous alternation in a loop, backreferences, lookarounds) for agents that write or accept regexes. Runs the caller's test subjects (up to 20, 1000 characters each) only when the pattern is proven polynomially bounded and the subject is short enough for that bound; otherwise reports the risk and runs nothing. A fail names a pattern with a provable exponential split; unknown means not proven safe, not proven unsafe. Does not translate other regex flavors.","roi":"A single ReDoS pattern pinned a Worker or Node loop in many public incidents; this checks before the regex ships.","audience":"developer","package":"code-preflight-kit","channels":["x402","mcp"],"endpoint":{"method":"POST","url":"https://agents.writerslogic.com/api/v1/regex-check","path":"/api/v1/regex-check","contentType":"application/json"},"price":{"amount":"0.005","currency":"USDC","network":"base","perCall":true,"failedCallsCharged":false},"inputSchema":{"type":"object","additionalProperties":false,"required":["pattern"],"properties":{"pattern":{"type":"string","maxLength":500,"description":"ECMAScript regex source, without slashes."},"flags":{"type":"string","maxLength":8,"description":"Flags among dgimsuy (v is reported unsupported).","pattern":"^[dgimsuvy]*$"},"cases":{"type":"array","maxItems":20,"items":{"type":"object","additionalProperties":false,"required":["subject"],"properties":{"subject":{"type":"string","maxLength":1000},"expectMatch":{"type":"boolean"}}},"description":"Subjects to test; at most 10000 characters in total."}}},"resultSchema":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail","unknown","unsupported"],"description":"pass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass."},"pattern":{"type":"string"},"flags":{"type":"string"},"valid":{"type":"boolean"},"executed":{"type":"boolean"},"degree":{"type":"integer","description":"Worst-case step growth exponent in subject length (1 + number of unbounded quantifiers on an unanchored search)."},"subjectCap":{"type":"integer","description":"Longest subject this pattern may run on within the step budget; 0 when execution is refused."},"risks":{"type":"array","items":{"type":"object","properties":{"rule":{"type":"string"},"severity":{"type":"string","enum":["high","unproven"]},"at":{"type":"integer"},"detail":{"type":"string"}}}},"cases":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer"},"ran":{"type":"boolean"},"skipped":{"type":"string"},"matched":{"type":"boolean"},"matchIndex":{"type":"integer"},"match":{"type":"string"},"groups":{"type":"integer"}}}},"witnesses":{"type":"array","items":{"type":"object","properties":{"ruleId":{"type":"string"},"detail":{"type":"string"},"path":{"type":"string","description":"JSON pointer or dotted path into the input."},"offset":{"type":"integer"},"index":{"type":"integer"},"expected":{"description":"What the rule required."},"actual":{"description":"What the input had."}}}},"versions":{"type":"object","description":"Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile)."},"limits":{"type":"array","items":{"type":"string"}},"deterministic":{"type":"boolean","description":"Always true: pure code, no model."}}},"outputSchema":{"type":"object","properties":{"data":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail","unknown","unsupported"],"description":"pass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass."},"pattern":{"type":"string"},"flags":{"type":"string"},"valid":{"type":"boolean"},"executed":{"type":"boolean"},"degree":{"type":"integer","description":"Worst-case step growth exponent in subject length (1 + number of unbounded quantifiers on an unanchored search)."},"subjectCap":{"type":"integer","description":"Longest subject this pattern may run on within the step budget; 0 when execution is refused."},"risks":{"type":"array","items":{"type":"object","properties":{"rule":{"type":"string"},"severity":{"type":"string","enum":["high","unproven"]},"at":{"type":"integer"},"detail":{"type":"string"}}}},"cases":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer"},"ran":{"type":"boolean"},"skipped":{"type":"string"},"matched":{"type":"boolean"},"matchIndex":{"type":"integer"},"match":{"type":"string"},"groups":{"type":"integer"}}}},"witnesses":{"type":"array","items":{"type":"object","properties":{"ruleId":{"type":"string"},"detail":{"type":"string"},"path":{"type":"string","description":"JSON pointer or dotted path into the input."},"offset":{"type":"integer"},"index":{"type":"integer"},"expected":{"description":"What the rule required."},"actual":{"description":"What the input had."}}}},"versions":{"type":"object","description":"Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile)."},"limits":{"type":"array","items":{"type":"string"}},"deterministic":{"type":"boolean","description":"Always true: pure code, no model."}}},"_provenance":{"type":"object","description":"C2PA-aligned manifest and W3C VC 2.0 (eddsa-jcs-2022) issued by the hub DID; verify at POST /api/v1/verify-provenance"}},"required":["data","_provenance"]},"example":{"pattern":"^(\\w+\\s?)*$","cases":[{"subject":"hello world","expectMatch":true}]},"openapiOperation":{"operationId":"regex_check","summary":"Regex catastrophic-backtracking check, then test cases only if proven safe","description":"Statically analyses an ECMAScript regular expression (up to 500 characters) for catastrophic backtracking (nested or overlapping quantifiers, ambiguous alternation in a loop, backreferences, lookarounds) for agents that write or accept regexes. Runs the caller's test subjects (up to 20, 1000 characters each) only when the pattern is proven polynomially bounded and the subject is short enough for that bound; otherwise reports the risk and runs nothing. A fail names a pattern with a provable exponential split; unknown means not proven safe, not proven unsafe. Does not translate other regex flavors.\n\nPrice: 0.005 USDC on Base (x402).","x-x402-price-usdc":"0.005","x-x402-amount":"5000","x-payment-info":{"protocols":["x402"],"price":{"mode":"fixed","currency":"USD","amount":"0.005"}},"x-audience":"developer","x-sample-url":"https://agents.writerslogic.com/api/v1/samples/regex-check","security":[{"x402":[]},{"apiKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["pattern"],"properties":{"pattern":{"type":"string","maxLength":500,"description":"ECMAScript regex source, without slashes."},"flags":{"type":"string","maxLength":8,"description":"Flags among dgimsuy (v is reported unsupported).","pattern":"^[dgimsuvy]*$"},"cases":{"type":"array","maxItems":20,"items":{"type":"object","additionalProperties":false,"required":["subject"],"properties":{"subject":{"type":"string","maxLength":1000},"expectMatch":{"type":"boolean"}}},"description":"Subjects to test; at most 10000 characters in total."}}},"example":{"pattern":"^(\\w+\\s?)*$","cases":[{"subject":"hello world","expectMatch":true}]}}}},"responses":{"200":{"description":"Paid result with provenance","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail","unknown","unsupported"],"description":"pass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass."},"pattern":{"type":"string"},"flags":{"type":"string"},"valid":{"type":"boolean"},"executed":{"type":"boolean"},"degree":{"type":"integer","description":"Worst-case step growth exponent in subject length (1 + number of unbounded quantifiers on an unanchored search)."},"subjectCap":{"type":"integer","description":"Longest subject this pattern may run on within the step budget; 0 when execution is refused."},"risks":{"type":"array","items":{"type":"object","properties":{"rule":{"type":"string"},"severity":{"type":"string","enum":["high","unproven"]},"at":{"type":"integer"},"detail":{"type":"string"}}}},"cases":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer"},"ran":{"type":"boolean"},"skipped":{"type":"string"},"matched":{"type":"boolean"},"matchIndex":{"type":"integer"},"match":{"type":"string"},"groups":{"type":"integer"}}}},"witnesses":{"type":"array","items":{"type":"object","properties":{"ruleId":{"type":"string"},"detail":{"type":"string"},"path":{"type":"string","description":"JSON pointer or dotted path into the input."},"offset":{"type":"integer"},"index":{"type":"integer"},"expected":{"description":"What the rule required."},"actual":{"description":"What the input had."}}}},"versions":{"type":"object","description":"Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile)."},"limits":{"type":"array","items":{"type":"string"}},"deterministic":{"type":"boolean","description":"Always true: pure code, no model."}}},"_provenance":{"type":"object","description":"C2PA-aligned manifest and W3C VC 2.0 (eddsa-jcs-2022) issued by the hub DID; verify at POST /api/v1/verify-provenance"}},"required":["data","_provenance"]}}}},"400":{"description":"Invalid request (no payment consumed)","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}}}}},"401":{"description":"Invalid X-API-KEY","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}}}}},"402":{"description":"Payment required or invalid","content":{"application/json":{"schema":{"type":"object","description":"x402 v2 PaymentRequired (also base64 in the PAYMENT-REQUIRED header)","properties":{"x402Version":{"type":"integer"},"error":{"type":"string"},"code":{"type":"string"},"resource":{"type":"object"},"accepts":{"type":"array","items":{"type":"object"}},"extensions":{"type":"object"}}}}}},"502":{"description":"Upstream failure; the payment is released or not settled","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}}}}}}},"links":{"docs":"https://agents.writerslogic.com/docs/regex-check/","docsJson":"https://agents.writerslogic.com/docs/regex-check.json","sample":"https://agents.writerslogic.com/api/v1/samples/regex-check","openapi":"https://agents.writerslogic.com/openapi.json","catalog":"https://agents.writerslogic.com/api/v1/catalog","verifyProvenance":"https://agents.writerslogic.com/api/v1/verify-provenance","index":"https://agents.writerslogic.com/docs/index.json"}}