df-drills pandas · Polars · DuckDB SQL · DuckDB Relational 题目列表 登录

规范电话号码

中等 07-string 字符串 stringregexreplacevalidation

把 raw_customers.phone 规范成纯数字的手机号:

  1. 删除其中所有不是数字(0–9)的字符,例如 138-1234-5678 → 13812345678,+86 138 1234 5678 → 8613812345678。
  2. 删除后的结果如果恰好 11 位且以 1 开头,就输出它;否则(位数不对、首位不是 1、删完是空字符串)输出 null。
  3. phone 为 null 时输出 null。

数据里的数字都是普通的半角数字。

输入

  • raw_customers(id, full_name, email, phone, birthday, signup, vip, spend),所有列都是字符串。

输出

列为 id, phone,行数与输入相同(id 可能重复,照常输出),行顺序不限。

输入表 (case base,共 2 个 case:base、edge)

raw_customers messy/raw_customers
#idstringfull_namestringemailstringphonestringbirthdaystringsignupstringvipstringspendstring
1 1 xu ming xu.ming60@mail.cn +86 189 3287 9217 - 2025-02-12 YES 3428
2 2 yang guo yang.guo68@example.com 10033907579 2003-04-21 05/01/2025 n 2,132.69
3 3 guo jing guo.jing91@mail.cn 15384019161 01/02/1994 2025-01-01 Y 3716.67
4 4 zhou jie zhou.jie26@qq.com 14514506123 29/02/2000 01/07/2025 no 999.73
5 5 liu yang liu.yang51@mail.cn 13049403 31/04/1999 2025-09-22 0 2024
6 6 zhang san ZHANG.SAN@Example.COM 13095597297 06/07/1978 15/11/2025 no $1,200.50
7 7 null zhou.jie54@example.com (111) 08436469 2003.3.24 2025-08-22 N $4,809.60
8 8 BOB smith N/A 173-0024-5892 11/08/1978 2026-06-19 yes 4842.25
9 9 LI WEI li.wei40@example.com (109) 17145211 - 13/05/2025 0 3592.13
10 10 he ping he.ping54@example.com 179-0966-9091 14/05/1977 02/02/2026 n 4395.47
11 11 guo jing guo.jing4@mail.cn 19170317974 05/05/1993 2025-07-27 0 2,316.99
12 12 he ping he.ping86@mail.cn 136-3363-9532 1992-01-23 11/10/2025 N 1442.64
13 13 BOB smith bob.smith67@mail.cn 1971-11-05 2025-07-14 1 $738.58
14 14 WANG FANG wang.fang@@mail.com N/A 09/04/1981 07/07/2026 yes 4152.00
15 15 grace HOPPER grace.hopper93@mail.cn (127) 73068985 - 2025-05-07 YES 1624
16 16 guo jing guo.jing34@qq.com (105) 81075864 2025-02-05 0 4,802.51
17 17 LIU YANG liu.yang93@qq.com 17791378 16/11/2025 no 740.03
18 18 GUO JING guo.jing26@mail.cn 18180960808 04/10/2004 2025-06-20 n 4196.37
19 19 zhou jie zhou.jie17@mail.cn 167-8513-6904 1971-01-07 13/01/2025 0 free
20 20 CHEN JING chen.jing66@qq.com - 28/04/2003 2025-05-20 0 1656
显示前 20 行,共 80 行

期望输出 (case base,行顺序不限)

#idStringphoneString
1 1 null
2 2 10033907579
3 3 15384019161
4 4 14514506123
5 5 null
6 6 13095597297
7 7 11108436469
8 8 17300245892
9 9 10917145211
10 10 17909669091
11 11 19170317974
12 12 13633639532
13 13 null
14 14 null
15 15 12773068985
16 16 10581075864
17 17 null
18 18 18180960808
19 19 16785136904
20 20 null
21 21 null
22 22 13171008989
23 23 16856395003
24 24 16993895441
25 25 null
26 26 16014445888
27 27 null
28 28 12660560951
29 29 11096713058
30 30 null
31 31 null
32 32 16462529548
33 33 null
34 34 17847536831
35 35 null
36 36 10216337857
37 37 16178085016
38 38 14142207097
39 39 12488747658
40 40 13075736926
41 41 13221549817
42 42 null
43 43 17067349170
44 44 16154497576
45 45 11661568232
46 46 null
47 47 18390312379
48 48 11842592104
49 49 14699023670
50 50 12679175699
显示前 50 行,共 80 行