找回密码
 加入
搜索
查看: 74922|回复: 9

[AU3基础] [已解决]大家帮忙看看这个正则哪里有问题???

[复制链接]
发表于 2013-9-9 04:06:48 | 显示全部楼层 |阅读模式
本帖最后由 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&0008  The 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&0008  The device has the following problem: 01
大家帮忙看看哪里出错了
发表于 2013-9-9 11:06:17 | 显示全部楼层
#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)
 楼主| 发表于 2013-9-9 14:49:11 | 显示全部楼层
回复 2# afan
谢谢A版的帮忙 不过我还在消化中
 楼主| 发表于 2013-9-9 15:14:09 | 显示全部楼层
本帖最后由 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) 
发表于 2013-9-9 23:26:12 | 显示全部楼层
你只是标题只有“正则”二字,Afan就来了。呵呵!
Afan的正则就是犀利,这个没话说!
 楼主| 发表于 2013-9-10 01:09:40 | 显示全部楼层
回复 5# xlj310
到现在还没消化掉呢
太深奥了
发表于 2013-9-10 09:32:38 | 显示全部楼层
都来学习A版的正则,羡慕啊
发表于 2013-9-10 11:14:00 | 显示全部楼层
信afan,得永生,
 楼主| 发表于 2013-9-10 13:52:42 | 显示全部楼层
回复 8# leon460
看了一些A版的帖子及回复 确实是功底不凡
发表于 2018-10-13 16:57:13 | 显示全部楼层
練習
(?si)(.*?)Name:.*?(The device.+?m:\h+\d+)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-29 20:42 , Processed in 0.079161 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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