# pydantic.errors.StrRegexError: string does not match regex

- **ID:** `python/pydantic-anystr-strict-whitespace`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 2.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Use pattern='^[A-Z]+$' and ensure input is uppercase without spaces
   ```
2. **** (85% success)
   ```
   Strip whitespace before validation: @field_validator('field', mode='before') def strip(cls, v): return v.strip()
   ```

## Dead Ends

- **** — Pydantic uses re.match by default, but pattern must match entire string; partial matches fail. (75% fail)
- **** — Whitespace is not stripped unless configured; pattern fails. (80% fail)
