| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- # -*- coding: utf-8 -*-
- # 规则文件:电话号码提取
- # 源:template_extract/template_extractor.py get_phone() 第 62-72 行
- # assembly/role_money.py phone 编译 第 1043-1053 行
- # 迁移日期:2026-08-12 Phase 7
- # 注意:原代码在两处有高度相似但不完全相同的 phone_pattern 定义。
- # 本文件以 template_extractor.py 的版本为准统一,
- # role_money.py 的版本差异(部分分支不同)在后续迁移时评估合并。
- version: 1
- category: CONTACT
- description: |
- 电话号码提取(手机 + 座机 + 400 + 分机)。
- 原 template_extractor.get_phone() 使用 ^pattern$ 整串匹配验证。
- 原 role_money.py phone 使用 re.compile + finditer 扫描。
- 迁移后两处统一引用 RuleLoader.get_pattern("phone_extract")。
- patterns:
- - id: phone_extract
- description: |
- 通用电话号码提取。支持:
- - 手机号 1[3-9]xxxxxxxxx(含分隔符 -—-―)
- - +86 前缀手机
- - 座机 0xx-xxxxxxxx(含分机 / 转 分机)
- - 带前瞻的座机变体(避免误匹配)
- - 括号包裹的区号 (0xx)xxxxxxxx
- - 7-8 位号码
- pattern: '1[3-9][0-9][-—-―]?\d{4}[-—-―]?\d{4}|\+86.?1[3-9]\d{9}|0[1-9]\d{1,2}[-—-―][2-9]\d{6,7}/[1-9]\d{6,10}|0[1-9]\d{1,2}[-—-―][2-9]\d{6}\d?.?转\d{1,4}|0[1-9]\d{1,2}[-—-―][2-9]\d{6}\d?[-—-―]\d{1,4}|0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?(?=1[3-9]\d{9})|0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?(?=0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?)|0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?(?=[2-9]\d{6,7})|0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?|[\(|\(]0[1-9]\d{1,2}[\)|\)]-?[2-9]\d{6}\d?-?\d{,4}|[2-9]\d{6,7}'
- method: search
- golden_examples:
- - input: "13812345678"
- should_match: true
- - input: "138-1234-5678"
- should_match: true
- - input: "+8613812345678"
- should_match: true
- - input: "010-87654321"
- should_match: true
- - input: "010-87654321转1234"
- should_match: true
- - input: "(010)87654321"
- should_match: true
- - input: "87654321"
- should_match: true
- - input: "12345"
- should_match: false
- - input: "abcdefg"
- should_match: false
|