dtooboss 发表于 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.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.Graphics System.Windows.Forms.Control::CreateGraphics()
       IL_8acb:ldfld      class 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.Control::set_Text(string)
IL_0226:ldarg.0
    IL_0227:ldfld      class 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.ScrollingLabel::AddText(string)
    IL_0236:ldarg.0
    IL_0237:ldfld      class DistantWorlds.Controls.ScrollingLabel DistantWorlds.Start::MBFBkA


如何用正则表达 ldstr      bytearray ( )中的 16进制字符串并忽略掉其他字符?

3mile 发表于 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))

dtooboss 发表于 2010-4-21 23:28:06

本帖最后由 dtooboss 于 2010-4-21 23:35 编辑


水木子 发表于 2010-4-21 22:54 http://www.autoitx.com/images/common/back.gif

谢谢各位
不过最后会多个 ) .
还有,这个文件有几十万行。其中有很多这样的字串
我需要用 ldstr      bytearray 来做标识。

3mile 发表于 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)

nmgwddj 发表于 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))

dtooboss 发表于 2010-4-22 16:33:42

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

不知道还有什么好办法?
文件在30万--50万行。

3mile 发表于 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
页: [1]
查看完整版本: 正则求助