[CSharp]解析文件,还是用正则快

从BSC上得到告警
allip;

用程序去解?太累,还是用正则方便。


 
再用它生成代码
        //  using System.Text.RegularExpressions;

        
/// <summary>
        
///  Regular expression built for C# on: 星期五, 五月 12, 2006, 03:12:38 下午
        
///  Using Expresso Version: 2.1.1822, http://www.ultrapico.com
        
///  
        
///  A description of the regular expression:
        
///  
        
///  [1]: A numbered capture group. [\w{2}]
        
///      Alphanumeric, exactly 2 repetitions
        
///  /
        
///  [2]: A numbered capture group. [\w{3}]
        
///      Alphanumeric, exactly 3 repetitions
        
///  \s"
        
///      Whitespace
        
///  [3]: A numbered capture group. [\w+/\w+/\d+]
        
///      \w+/\w+/\d+
        
///          Alphanumeric, one or more repetitions
        
///          /
        
///          Alphanumeric, one or more repetitions
        
///          /
        
///          Any digit, one or more repetitions
        
///  "\s
        
///      "
        
///      Whitespace
        
///  [4]: A numbered capture group. [\d+], one or more repetitions
        
///      Any digit, one or more repetitions
        
///  Whitespace
        
///  [5]: A numbered capture group. [\d+], one or more repetitions
        
///      Any digit, one or more repetitions
        
///  Whitespace, one or more repetitions
        
///  [6]: A numbered capture group. [\d+]
        
///      Any digit, one or more repetitions
        
///  \s+\r\n
        
///      Whitespace, one or more repetitions
        
///      Carriage return
        
///      New line
        
///  [7]: A numbered capture group. [.*]
        
///      Any character, any number of repetitions
        
///  \r\n
        
///      Carriage return
        
///      New line
        
///  [8]: A numbered capture group. [.*]
        
///      Any character, any number of repetitions
        
///  \r\n\r\n
        
///      Carriage return
        
///      New line
        
///      Carriage return
        
///      New line
        
///  [9]: A numbered capture group. [.*]
        
///      Any character, any number of repetitions
        
///  \r\n
        
///      Carriage return
        
///      New line
        
///  [MO名称]: A named capture group. [.*?]
        
///      Any character, any number of repetitions, as few as possible
        
///  Whitespace, one or more repetitions
        
///  [10]: A numbered capture group. [?<基站名称>.*?]
        
///      ?<基站名称>.*?
        
///          ?<基站名称>
        
///          Any character, any number of repetitions, as few as possible
        
///  Whitespace, one or more repetitions
        
///  [11]: A numbered capture group. [.{1}]
        
///      Any character, exactly 1 repetitions
        
///  \r\n\r\n
        
///      Carriage return
        
///      New line
        
///      Carriage return
        
///      New line
        
///  [12]: A numbered capture group. [?<告警类型>.*]
        
///      ?<告警类型>.*
        
///          ?<告警类型>
        
///          Any character, any number of repetitions
        
///  \s*\r\n
        
///      Whitespace, any number of repetitions
        
///      Carriage return
        
///      New line
        
///  [13]: A numbered capture group. [?<告警内容>.*?]
        
///      ?<告警内容>.*?
        
///          ?<告警内容>
        
///          Any character, any number of repetitions, as few as possible
        
///  \s*\r\n\r\n\r\n\r\n
        
///      Whitespace, any number of repetitions
        
///      Carriage return
        
///      New line
        
///      Carriage return
        
///      New line
        
///      Carriage return
        
///      New line
        
///      Carriage return
        
///      New line
        
///  
        
///  
        
/// </summary>

        public static Regex EricssonBscAlarmRegex = new Regex(
            
@"(\w{2})/(\w{3})\s""(\w+/\w+/\d+)""\s(\d+)+\s(\d+)+\s+(\d+)\s"
            
+ @"+\r\n" + "\r\n" + @"(.*)\r\n" + "\r\n" + @"(.*)\r\n" + "\r\n" + @"\r\n" + "\r\n" + @"(.*)\r\n" + "\r\n" + @"(?<MO名称>.*?)\s+(?"
            
+ @"<基站名称>.*?)\s+(.{1})\r\n" + "\r\n" + @"\r\n" + "\r\n" + @"(?<告警类型>.*)\s*\r\n" + "\r\n" + @"(?<告警内容>."
            
+ @"*?)\s*\r\n" + "\r\n" + @"\r\n" + "\r\n" + @"\r\n" + "\r\n" + @"\r\n",
            RegexOptions.IgnoreCase
            
| RegexOptions.Multiline
            
| RegexOptions.CultureInvariant
            
| RegexOptions.IgnorePatternWhitespace
            
| RegexOptions.Compiled
            );
原文地址:https://www.cnblogs.com/xuzhong/p/398559.html