{
  "id": "python/pydantic-anystr-strict-whitespace",
  "signature": "pydantic.errors.StrRegexError: string does not match regex",
  "signature_zh": "pydantic.errors.StrRegexError: 字符串不符合正则表达式",
  "regex": "pydantic\\.errors\\.StrRegexError:\\ string\\ does\\ not\\ match\\ regex",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "When using Field(pattern=...) with a string, the input must fully match the regex; any mismatch raises StrRegexError, often due to whitespace or partial matches.",
  "root_cause_type": "generic",
  "root_cause_zh": "当使用 Field(pattern=...) 对字符串进行验证时，输入必须完全匹配正则表达式；任何不匹配（如空白字符或部分匹配）都会引发 StrRegexError。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Pydantic uses re.match by default, but pattern must match entire string; partial matches fail.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Whitespace is not stripped unless configured; pattern fails.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use pattern='^[A-Z]+$' and ensure input is uppercase without spaces",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Strip whitespace before validation: @field_validator('field', mode='before') def strip(cls, v): return v.strip()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}