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

[效率算法] 正则求助

  [复制链接]
发表于 2010-4-21 22:12:09 | 显示全部楼层 |阅读模式
本帖最后由 dtooboss 于 2010-4-22 00:43 编辑
IL_0763:  ldc.i4.0
    IL_0764:  callvirt   instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Visible(bool)
    IL_0769:  ldstr      bytearray (43 00 6F 00 70 00 79 00 72 00 69 00 67 00 68 00   // C.o.p.y.r.i.g.h.
                                    74 00 20 00 A9 00 32 00 30 00 31 00 30 00 20 00   // t. ...2.0.1.0. .
                                    43 00 6F 00 64 00 65 00 46 00 6F 00 72 00 63 00   // C.o.d.e.F.o.r.c.
                                    65 00 20 00 4C 00 69 00 6D 00 69 00 74 00 65 00   // e. .L.i.m.i.t.e.
                                    64 00 2E 00 20 00 41 00 6C 00 6C 00 20 00 72 00   // d... .A.l.l. .r.
                                    69 00 67 00 68 00 74 00 73 00 20 00 72 00 65 00   // i.g.h.t.s. .r.e.
                                    73 00 65 00 72 00 76 00 65 00 64 00 2E 00 )       // s.e.r.v.e.d...
    IL_076e:  stloc.s    V_7
    IL_0770:  ldarg.0
    IL_0771:  call       instance class [System.Drawing]System.Drawing.Graphics [System.Windows.Forms]System.Windows.Forms.Control::CreateGraphics()
       IL_8acb:  ldfld      class [System.Windows.Forms]System.Windows.Forms.LinkLabel DistantWorlds.Start::KMCGXNAsdtiGdVXAZYGGHuF
    IL_8ad0:  ldstr      bytearray (B0 65 84 76 38 6E 0F 62 )    //hrthr                     
    IL_8ad5:  callvirt   instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_0226:  ldarg.0
    IL_0227:  ldfld      class [DistantWorlds.Controls]DistantWorlds.Controls.ScrollingLabel DistantWorlds.Start::MBFBkA
    IL_022c:  ldstr      bytearray (43 00 6F 00 70 00 79 00 72 00 69 00 67 00 68 00   // C.o.p.y.r.i.g.h.
                                    74 00 20 00 A9 00 32 00 30 00 31 00 30 00 )       // t. ...2.0.1.0.
    IL_0231:  callvirt   instance void [DistantWorlds.Controls]DistantWorlds.Controls.ScrollingLabel::AddText(string)
    IL_0236:  ldarg.0
    IL_0237:  ldfld      class [DistantWorlds.Controls]DistantWorlds.Controls.ScrollingLabel DistantWorlds.Start::MBFBkA
如何用正则表达 ldstr      bytearray ( )  中的 16进制字符串并忽略掉其他字符?
发表于 2010-4-21 22:53:03 | 显示全部楼层
#include <array.au3>
$str=FileRead("1.txt");1.txt文件内容为楼主提供字符串
$arr=StringRegExp($str,'[\dA-F][\dA-F]\s',3)
_ArrayDisplay($arr)
发表于 2010-4-21 22:54:41 | 显示全部楼层
#include <Array.au3>
$sReg = StringRegExp(FileRead(@ScriptDir & '\Text.txt'), '(\d{2}\s00.+?)\)*//', 3)  ;将文本保存到脚本同目录下的 Text.txt文件里
MsgBox(0, '', _ArrayToString($sReg, @CRLF))
 楼主| 发表于 2010-4-21 23:28:06 | 显示全部楼层
本帖最后由 dtooboss 于 2010-4-21 23:35 编辑
水木子 发表于 2010-4-21 22:54


谢谢各位
不过最后会多个 ) .
还有,这个文件有几十万行。其中有很多这样的字串
我需要用 ldstr      bytearray 来做标识。
发表于 2010-4-22 10:49:17 | 显示全部楼层
这段代码也许是因为数组容量的限制,只能写成这样了。
#include <array.au3>
#include <string.au3>
If FileExists("2.txt") Then FileDelete("2.txt")
If FileExists("3.txt") Then FileDelete("3.txt")
Dim $i=1
While 1
$str=FileReadLine("1.txt",$i);1.txt文件内容为楼主提供字符串
If $str="" Then ExitLoop
If StringInStr($str,"ldstr      bytearray") Then 
        FileWrite("2.txt",$str)
Else
        If StringInStr($str,"//") Then FileWrite("2.txt",$str)
EndIf

$i+=1
WEnd
$str1=StringRegExpReplace(FileRead("2.txt"),'\/\/.{1,20}\s','')
$str1=StringStripWS ( $str1, 4)
FileWrite("3.txt",$str1)
$arr = _StringBetween($str1, '(', ')')
_ArrayDisplay($arr)

评分

参与人数 1金钱 +30 贡献 +2 收起 理由
dtooboss + 30 + 2 学习了

查看全部评分

发表于 2010-4-22 11:37:48 | 显示全部楼层
太强悍了 正则
发表于 2010-4-22 12:02:56 | 显示全部楼层
本帖最后由 水木子 于 2010-4-22 12:22 编辑

回复 4# dtooboss
不好意思啊!昨晚写得比较匆忙没注意这问题。
下面这样应该就可以了吧!
#include <Array.au3>
$Text = StringRegExpReplace(FileRead(@ScriptDir & '\Text.txt'), '\(|\)', '') ;将需要处理的文本保存到脚本同目录下Text.txt文件里
$sReg = StringRegExp($Text, '(\w{2}\s\w{2}.*)\)*\s//', 3)
MsgBox(0, '', _ArrayToString($sReg, @CRLF))

评分

参与人数 1金钱 +30 贡献 +2 收起 理由
dtooboss + 30 + 2 学习了

查看全部评分

 楼主| 发表于 2010-4-22 16:33:42 | 显示全部楼层
再次感谢各位高手相助。
经验证,各位高手所有的表达式都能准确实现要求。
不过用读行来处理这个大文本,已经力不从心。太慢了........
我试了用数组和行来读,程序跑了几小时,到后来越来越慢,开始几分钟每秒还能处理100行
后来越来越慢,到后来每秒只能处理2行。

不知道还有什么好办法?
文件在30万--50万行。
发表于 2010-4-22 17:47:49 | 显示全部楼层
再试试这个,30万-50万行的东东?估计够呛
#include <array.au3>
$str=FileRead("1.txt");1.txt文件内容为楼主提供字符串
$arr=StringRegExp($str,'\s\([^()]*\)',3)
;_ArrayDisplay($arr)
For $i=0 To UBound($arr)-1
        ;MsgBox(0,0,$arr[$i])
        $str1=StringRegExpReplace($arr[$i],'\/\/.{1,20}\s','')
        $str1=StringStripWS ( $str1, 4)
        FileWrite("temp.txt",$str1&@CRLF)
Next
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-16 06:51 , Processed in 0.085180 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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