# AssertionError: 正则表达式模式 '\d+' 不匹配 'abc'。
assert regex_search('\d+', 'abc')

- **ID:** `python/pytest-assert-regex-mismatch`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用 pytest 的 `re.match` 或 `assert re.search` 的测试失败，因为字符串不包含预期的模式，通常是由于正则表达式错误或输入错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Test the regex separately: `import re; assert re.search(r'\d+', 'abc123')` to verify the pattern works.
   ```
2. **** (95% 成功率)
   ```
   Use raw strings for regex patterns to avoid escape issues: `r'\d+'`
   ```

## 无效尝试

- **** — This may not capture the exact pattern requirements and can lead to false passes. (70% 失败率)
- **** — This makes the test useless as it matches anything, defeating the purpose of validation. (85% 失败率)
