找回密码
 加入
搜索
查看: 5583|回复: 8

[效率算法] 问个查询文本内容的问题

  [复制链接]
发表于 2011-7-10 19:47:58 | 显示全部楼层 |阅读模式
6/1/2011 8:56:9 - PFRO Error: \??\C:\Users\Administrator\AppData\Roaming\Tencent\QQ\AUTemp\L(2T]}%BH7%I09CDJV@V0B1\1305880992493657663, |delete operation|, 0xc0000101
6/1/2011 8:56:9 - 8 Successful PFRO operations

6/4/2011 9:6:8 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\12074065\, |delete operation|, 0xc0000101
6/4/2011 9:6:8 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\4f7aec4d\, |delete operation|, 0xc0000101
6/4/2011 9:6:8 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\5f7adcac\, |delete operation|, 0xc0000101
6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\9194849a\, |delete operation|, 0xc0000101
6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\dee01ee0\, |delete operation|, 0xc0000101
6/4/2011 9:6:9 - PFRO Error: \??\C:\Program Files (x86)\Common Files\Tencent\QQPhotoDrawEx\QQPhotoDrawEx.2.27.171.429.dll, |delete operation|, 0xc0000034
6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\4e68af1b\, |delete operation|, 0xc0000101
6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\829fb9ce\, |delete operation|, 0xc0000101
6/4/2011 9:6:9 - PFRO Error: \??\C:\Program Files (x86)\Common Files\Tencent\QQPhotoDrawEx\QQPhotoDrawEx.2.27.171.429.dll, |delete operation|, 0xc0000034
6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\dd63124c\, |delete operation|, 0xc0000101
6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\801dbe41\, |delete operation|, 0xc0000101
6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\821fb8ef\, |delete operation|, 0xc0000101
6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\cde02309\, |delete operation|, 0xc0000101
6/4/2011 9:6:9 - 1 Successful PFRO operations

6/5/2011 10:2:53 - PFRO Error: \??\C:\ProgramData\Tencent\QQPinyin\Repair\, |delete operation|, 0xc0000101
6/5/2011 10:2:54 - 141 Successful PFRO operations

6/28/2011 9:21:37 - PFRO Error: \??\C:\ProgramData\Tencent\QQPinyin\Repair\, |delete operation|, 0xc0000101
6/28/2011 9:21:37 - 141 Successful PFRO operations
上面是一个文本文件的内容,想得到包含“0xc0000101”的行数,应该怎么做
发表于 2011-7-10 21:10:49 | 显示全部楼层
#include <Array.au3>
Local $Str = _
                '6/1/2011 8:56:9 - PFRO Error: \??\C:\Users\Administrator\AppData\Roaming\Tencent\QQ\AUTemp\L(2T]}%BH7%I09CDJV@V0B1\1305880992493657663, |delete operation|, 0xc0000101' & @CRLF & _
                '6/1/2011 8:56:9 - 8 Successful PFRO operations' & @CRLF & @CRLF & _
                '6/4/2011 9:6:8 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\12074065\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:8 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\4f7aec4d\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:8 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\5f7adcac\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\9194849a\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\dee01ee0\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Program Files (x86)\Common Files\Tencent\QQPhotoDrawEx\QQPhotoDrawEx.2.27.171.429.dll, |delete operation|, 0xc0000034' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\4e68af1b\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\829fb9ce\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Program Files (x86)\Common Files\Tencent\QQPhotoDrawEx\QQPhotoDrawEx.2.27.171.429.dll, |delete operation|, 0xc0000034' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\dd63124c\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\801dbe41\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\821fb8ef\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\cde02309\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - 1 Successful PFRO operations' & @CRLF & @CRLF & _
                '6/5/2011 10:2:53 - PFRO Error: \??\C:\ProgramData\Tencent\QQPinyin\Repair\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/5/2011 10:2:54 - 141 Successful PFRO operations' & @CRLF & @CRLF & _
                '6/28/2011 9:21:37 - PFRO Error: \??\C:\ProgramData\Tencent\QQPinyin\Repair\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/28/2011 9:21:37 - 141 Successful PFRO operations' & @CRLF & _
                '这一行是增加的,测试匹配不仅仅是行尾6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\cde02309\, |delete operation|, 0xc0000101 这里增加了测试'
MsgBox(0, '原字符串', $Str)
;Local $Test = StringRegExp($str, '(?m)^.*?0x[a-fA-F0-9]+', 3);如果要匹配包含所有16进制的行时用这句
;Local $Test = StringRegExp($str, '(?m)^.*?0xc0000101(?=[\r\n])', 3);如果0xc0000101必须在行尾才匹配的话用这句
Local $Test = StringRegExp($str, '(?m)^.*?0xc0000101(?(?![\r\n]).*)', 3);如果0xc0000101在行中间也匹配的话用这句
If Not @Error Then MsgBox(0, '匹配数量: ' & UBound($Test), '其中[0]元素为: ' & $Test[0])
_ArrayDisplay($Test, UBound($Test))

评分

参与人数 1金钱 +10 收起 理由
lpxx + 10 正则运用的好

查看全部评分

发表于 2011-7-10 23:08:05 | 显示全部楼层
3maile,学习了
发表于 2011-7-11 00:50:38 | 显示全部楼层
同样受教极多!
 楼主| 发表于 2011-7-11 01:29:57 | 显示全部楼层
非常感谢3mile
发表于 2011-7-11 07:20:12 | 显示全部楼层
本帖最后由 netegg 于 2011-7-11 07:31 编辑

行数还是行号,如果是文本,大可以不用正则
_filereadtoarray()
$aIndex = _arrayfindall() -----这是所有的行号
msgbox(0,0,ubound($aIndex)) -----这是行数

如果文本很大,还是用正则吧,array可能要受限制
发表于 2011-7-11 08:18:49 | 显示全部楼层
3mile哥威武。。。
发表于 2011-7-11 10:58:53 | 显示全部楼层
本帖最后由 shenrenba 于 2011-7-11 11:00 编辑

另一种方法
Local $Str = _
                '6/1/2011 8:56:9 - PFRO Error: \??\C:\Users\Administrator\AppData\Roaming\Tencent\QQ\AUTemp\L(2T]}%BH7%I09CDJV@V0B1\1305880992493657663, |delete operation|, 0xc0000101' & @CRLF & _
                '6/1/2011 8:56:9 - 8 Successful PFRO operations' & @CRLF & @CRLF & _
                '6/4/2011 9:6:8 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\12074065\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:8 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\4f7aec4d\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:8 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\5f7adcac\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\9194849a\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\dee01ee0\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Program Files (x86)\Common Files\Tencent\QQPhotoDrawEx\QQPhotoDrawEx.2.27.171.429.dll, |delete operation|, 0xc0000034' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\4e68af1b\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\829fb9ce\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Program Files (x86)\Common Files\Tencent\QQPhotoDrawEx\QQPhotoDrawEx.2.27.171.429.dll, |delete operation|, 0xc0000034' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\dd63124c\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\801dbe41\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\821fb8ef\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\cde02309\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/4/2011 9:6:9 - 1 Successful PFRO operations' & @CRLF & @CRLF & _
                '6/5/2011 10:2:53 - PFRO Error: \??\C:\ProgramData\Tencent\QQPinyin\Repair\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/5/2011 10:2:54 - 141 Successful PFRO operations' & @CRLF & @CRLF & _
                '6/28/2011 9:21:37 - PFRO Error: \??\C:\ProgramData\Tencent\QQPinyin\Repair\, |delete operation|, 0xc0000101' & @CRLF & _
                '6/28/2011 9:21:37 - 141 Successful PFRO operations' & @CRLF & _
                '这一行是增加的,测试匹配不仅仅是行尾6/4/2011 9:6:9 - PFRO Error: \??\C:\Users\ADMINI~1\AppData\Local\Temp\VMwareDnD\cde02309\, |delete operation|, 0xc0000101 这里增加了测试'
;上面这是3M的内容 我直接复制的
If StringRegExpReplace($str, '(?i).+?0xc0000101(?:\r\n|$)',"") Then MsgBox(0,0,@extended)
发表于 2011-7-12 09:15:32 | 显示全部楼层
太复杂了,但是用到
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-26 01:10 , Processed in 0.077528 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表