2014-03-05T03:49:43+08:00 autelanmaster eag1_0[1421]: eag_radius.c:1002:RadiusAcctRequestUpdate___UserName:73570,UserIP:20.3.141.241,Sessiontime:7200,SSID:shanlink,authtype:Portal,ApMAC:00-1F-64-EB-7C-CC,UserMAC:F8-A4-5F-C8-E9-B3,NasID:1用ruby写的代码如下(其实我的编码水平就是个菜头):
1 #!/usr/bin/env ruby
2 #
3 str = '2014-03-05T03:49:43+08:00 autelanmaster eag1_0[1421]: eag_radius.c:1002:RadiusAcctRequestUpdate___UserName:73570,UserIP:20.3.141.241,Sessiontime:7200,SSID:shanlink,authtype:Portal,ApMAC:00-1F-64-EB-7C-CC,UserMAC:F8-A4-5F-C8-E9-B3,NasID:1'
4 value = str.match /(^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}) (\w+)\s(\w+\d_\d\[\d{4}\]:)\s(\w+_\w+\.\w:\d+:\w+__\w+:\d+\,\w+:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\,\w+:\d+,\w+:)(shanlink)(,\w+:\w+,\w+:)([0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A- F]{2}-[0-9A-F]{2})(\,\w+:)([0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2})(\,\w+:\d)$/
5 puts value[1, 5, 9, 12]
我要得到的结果是value的 [1,5,9,11] .这段代码还不是正确的。不过要拿出来已经很容易了。
应该有更好的办法的,只是我现在不知道而已!