13682219949   
13609026805  13808881517
13609783767、81582096     
13719303210、020-39799567     
81562509   13602834507
13380020191、13725483283(new13719423311\13719423311  13824471313)     
13609003381、81781019   13025118425
81494349/13533388499/13660704340     
81903839\81980919  88575486     
00852-63323886/00852-24531630   00852-90180039
(0)13702680636、81025002     
13602848856、(020)83390862     
13922408386   13570257844(陈小姐)     就是一列这种的数据,用什么方法能把他们分成两列,一列放家庭号码,一列放手机号码

解决方案 »

  1.   


    --> 测试数据:@T
    declare @T table([col] varchar(100))
    insert @T
    select '13682219949' union all
    select '13609026805  13808881517' union all
    select '13609783767、81582096' union all
    select '13719303210、020-39799567' union all
    select '81562509 13602834507' union all
    select '13380020191、13725483283(new13719423311\13719423311  13824471313)' union all
    select '13609003381、81781019  13025118425' union all
    select '81494349/13533388499/13660704340' union all
    select '81903839\81980919  88575486' union all
    select '00852-63323886/00852-24531630  00852-90180039' union all
    select '(0)13702680636、81025002' union all
    select '13602848856、(020)83390862' union all
    select '13922408386  13570257844(陈小姐)'select * from @T
    /*
    col
    ----------------------------------------------------------------------------------------------------
    13682219949
    13609026805  13808881517
    13609783767、81582096
    13719303210、020-39799567
    81562509 13602834507
    13380020191、13725483283(new13719423311\13719423311  13824471313)
    13609003381、81781019  13025118425
    81494349/13533388499/13660704340
    81903839\81980919  88575486
    00852-63323886/00852-24531630  00852-90180039
    (0)13702680636、81025002
    13602848856、(020)83390862
    13922408386  13570257844(陈小姐)
    */建议在程序中用正则处理,不建议在数据库中处理。
      

  2.   

     string str = @"13682219949   
    13609026805  13808881517
    13609783767、81582096     
    13719303210、020-39799567     
    81562509   13602834507
    13380020191、13725483283(new13719423311\13719423311  13824471313)     
    13609003381、81781019   13025118425
    81494349/13533388499/13660704340     
    81903839\81980919  88575486     
    00852-63323886/00852-24531630   00852-90180039
    (0)13702680636、81025002     
    13602848856、(020)83390862     
    13922408386   13570257844(陈小姐)";
                List<string> mobile_list = Regex.Matches(str, @"((\+86)|(86))?(13)\d{9}").OfType<Match>().Select(a=>a.Value).ToList();
                /*
                 *  [0] "13682219949" string
    [1] "13609026805" string
    [2] "13808881517" string
    [3] "13609783767" string
    [4] "13719303210" string
    [5] "13602834507" string
    [6] "13380020191" string
    [7] "13725483283" string
    [8] "13719423311" string
    [9] "13719423311" string
    [10] "13824471313" string
    [11] "13609003381" string
    [12] "13025118425" string
    [13] "13533388499" string
    [14] "13660704340" string
    [15] "13702680636" string
    [16] "13602848856" string
    [17] "13922408386" string
    [18] "13570257844" string             */            List<string> phone_list = Regex.Matches(str, @"(?<=\D|(\s|/)0)([\((]\d{3,4}[\))]|\d{3,4}-)?\d{8}(?=\D)").OfType<Match>().Select(a => a.Value).ToList();
                /*
                  [0] "81582096" string
    [1] "020-39799567" string
    [2] "81562509" string
    [3] "81781019" string
    [4] "81494349" string
    [5] "81903839" string
    [6] "81980919" string
    [7] "88575486" string
    [8] "0852-63323886" string
    [9] "0852-24531630" string
    [10] "0852-90180039" string
    [11] "81025002" string
    [12] "(020)83390862" string 
                 */
      

  3.   


    请教一个问题,这些不要返回List而是返回字符串string应该怎么写?
    例如:
      string Mobile= "13609026805/13808881517";
      string Phone="0852-63323886/0852-24531630/0852-90180039";
    也就是说匹配完一行之后 就返回用Mobile和Phone接收