如果满足上面情况A:
 CNY13854.00     HXJ03P 
 081-1358032939         081-1358032940  提取:
 13854.00     
 HYJ03P 
 081-1358032939         
 081-1358032940 如果满足上面情况B:
 CNY13854.00     QDKI6 
 081-1358032939
提取:
 13854.00     
 HYJ03P 
 081-1358032939如果满足上面情况C:
 CNY13854.00     QQ456E 
 081-1358032939-40提取:
 13854.00     
 HYJ03P 
 081         
 1358032939-40      如果满足上面情况D:
 CNY13854.00     JYR31T 
 081-1358032939-40 081-1358032941-42提取:
 13854.00     
 HYJ03P 
 081-1358032939-40   
 081-1358032941-42
    

解决方案 »

  1.   

    看起来好复杂,我只能路过....发现题目好像有点问题吧!B。C。D中情况的 HYJ03P 哪里来的?
      

  2.   

    (?n)CNY(?<n1>\d+(?:\.\d{2})?)\s*(?<mask>.+)\s*(((?<tel>\d+-\d+(?!-)\b)\s*)+|((?<tel>\d+-\d+-\d+(?!-)\b)\s*){2,}|(?<tel1>\d+)-(?<tel2>\d+-\d+)\s*)$
      

  3.   

    public void Test()
    {
        string[] test = new string[]
        {
            "CNY13854.00 HXJ03P  \r\n081-1358032939 081-1358032940",
            "CNY13854.00 QDKI6  \r\n081-1358032939",
            "CNY13854.00 QQ456E  \r\n081-1358032939-40",
            "CNY13854.00 JYR31T  \r\n081-1358032939-40 081-1358032941-42"
        };
        Regex reg = new Regex(@"(?n)CNY(?<n1>\d+(?:\.\d{2})?)\s*(?<mask>.+)\s*(((?<tel>\d+-\d+(?!-)\b)\s*)+|((?<tel>\d+-\d+-\d+(?!-)\b)\s*){2,}|(?<tel1>\d+)-(?<tel2>\d+-\d+)\s*)$", RegexOptions.Compiled);
        foreach (string s in test)
        {
            Match m = reg.Match(s);
            Console.WriteLine(m.Groups["n1"].Value);
            Console.WriteLine(m.Groups["mask"].Value);
            if (m.Groups["tel"].Success)
            {
                foreach (Capture c in m.Groups["tel"].Captures)
                {
                    Console.WriteLine(c.Value);
                }
            }
            else
            {
                for (int i = 0; i < m.Groups["tel1"].Captures.Count; i++)
                {
                    Console.WriteLine(m.Groups["tel1"].Captures[i].Value);
                    Console.WriteLine(m.Groups["tel2"].Captures[i].Value);
                }
            }
            Console.WriteLine();
        }
    }输出
    13854.00
    HXJ03P
    081-1358032939
    081-135803294013854.00
    QDKI6
    081-135803293913854.00
    QQ456E
    081
    1358032939-4013854.00
    JYR31T
    081-1358032939-40
    081-1358032941-42
      

  4.   

    (?n)CNY(? <n1>\d+(?:\.\d{2})?)\s*(? <mask>.+)\s*(((? <tel>\d+-\d+(?!-)\b)\s*)+|((? <tel>\d+-\d+-\d+(?!-)\b)\s*){2,}|(? <tel1>\d+)-(? <tel2>\d+-\d+)\s*)$