[已解决]大家帮忙看看这个正则哪里有问题???
本帖最后由 PEM-System 于 2013-9-10 13:53 编辑以下是1.txt的内容
=================================
USB\VID_0BDA&PID_0139\20100201396000000
Name: USB2.0-CRW
The device has the following problem: 28
PCI\VEN_10DE&DEV_0DF4&SUBSYS_15F21043&REV_A1\4&CAD05E7&0&0008
Name: The device has the following problem: 01
=========================================#include <array.au3>
#include <file.au3>
Local $var = FileOpenDialog("请选择要开启的档案", "c:\data", " TXT(*.txt) ")
Local $file = FileOpen($var)
$line = FileRead($file)
Local $str2 = StringRegExpReplace($line, "Name: *","" )
$str = StringRegExp($str2, ".*\\.*\n.*The\sdevice.*", 3)
_ArrayDisplay($str)显示的是这样 为什么不配对另外一条呢
PCI\VEN_10DE&DEV_0DF4&SUBSYS_15F21043&REV_A1\4&CAD05E7&0&0008The device has the following problem: 01
而我希望得到下面的内容
USB\VID_0BDA&PID_0139\20100201396000000 The device has the following problem: 28
PCI\VEN_10DE&DEV_0DF4&SUBSYS_15F21043&REV_A1\4&CAD05E7&0&0008The device has the following problem: 01
大家帮忙看看哪里出错了 #include <array.au3>
Local $File = FileOpenDialog("请选择要开启的档案", "c:\data", " TXT(*.txt) ")
Local $sFile = FileRead($File)
Local $str = StringRegExpReplace($sFile, '(?si)\h{4}Name:.+?(?=\h{4})', '')
Local $aSR = StringRegExp($str, '(?mi)^.*?\\[\S\s]*?m:\h*\d*', 3)
_ArrayDisplay($aSR) 回复 2# afan
谢谢A版的帮忙 不过我还在消化中 本帖最后由 PEM-System 于 2013-9-9 15:17 编辑
去掉了一些多余的代码 不过还是很绕 不能一次解决 代码如下#include <array.au3>
#include <file.au3>
#include <1.au3>
Local $var = "2b.txt"
Local $file = FileOpen($var)
Local $line = FileRead($file)
Local $i
Local $str = StringRegExp($line, ".*\\.*\n.*The\sdevice.*", 3)
_ArrayDisplay($str)
你只是标题只有“正则”二字,Afan就来了。呵呵!
Afan的正则就是犀利,这个没话说! 回复 5# xlj310
到现在还没消化掉呢
太深奥了 都来学习A版的正则,羡慕啊 信afan,得永生,{:face (303):} 回复 8# leon460
看了一些A版的帖子及回复 确实是功底不凡 練習
(?si)(.*?)Name:.*?(The device.+?m:\h+\d+)
页:
[1]