ora-011 **************************
ora-01615 ******************************
ora-1001 ************************
......"*"号代码任意字符现在要将每一行的ORA-011这类的字符串单独截取出来.应该怎么做呢?

解决方案 »

  1.   

    正则表达式:
    ^ora-\d+
      

  2.   

    Regex r1 = new Regex("^ora-\\d+");
    string sErr = "ORA-24343: 用户自定义的回调错误 "
    foreach ( Match m in r1.Matches(sErr) )
    {
         sErr = m.Value;
    }
    数字后面应该是空格,刚才说错了.不好意思,不知道会不会影响结果.但是得到的结果的确不是我想要的..我只需要sErr的值为"ora-24343",但是得到的仍然是"ORA-24343: 用户自定义的回调错误 "
      

  3.   

    using System;
    using System.Text.RegularExpressions;class Program
    {
      static void Main()
      {
        string text = @"
    ora-011 ************************** 
    ora-01615 ****************************** 
    ora-1001 ************************ 
    ......"; 
        MatchCollection ms = Regex.Matches(text, @"(?m)^ora-\d+");
        foreach (Match m in ms)
        {
          Console.WriteLine(m.Value);
        } 
      }
    }
    /* 程序输出:
    ora-011
    ora-01615
    ora-1001
    */ 
      

  4.   

    using System;
    using System.Text.RegularExpressions;class Program
    {
      static void Main()
      {
        Regex r1 = new Regex("(?mi)^ora-\\d+");
        string sErr = "ORA-24343: 用户自定义的回调错误 ";
        foreach ( Match m in r1.Matches(sErr) )
        {
          sErr = m.Value;
          Console.WriteLine(sErr);   // 输出:ORA-24343
        }
      }
    }