找回密码
 加入
搜索
查看: 2540|回复: 4

[AU3基础] [已解决]关于正则获取字段中括号的值

  [复制链接]
发表于 2011-9-20 10:35:43 | 显示全部楼层 |阅读模式
本帖最后由 xyhqqaa 于 2011-9-20 14:03 编辑


想用everest获取电脑配置信息。。。在生成的配置文件中有
[Summary]
Partitions|Partition1=C: (NTFS) 30004 MB (19314 MB free)
Partitions|Partition2=D: (NTFS) 25603 MB (24223 MB free)
Partitions|Partition3=E: (NTFS) 230000 MB (87171 MB free)
Partitions|Partition4=F: (NTFS) 216932 MB (160868 MB free)
Partitions|Partition5=G: (NTFS) 226314 MB (151415 MB free)
Partitions|Partition6=H: (NTFS) 225019 MB (36250 MB free)
Partitions|Partition7=X: (NTFS) 112639 MB (2014 MB free)
Partitions|Total Size=1041.5 GB (470.0 GB free)
。就是想提取括号内的数值归类到相应位置,现在就是不知道用什么方法。有人建议说用正则。但俺 囧。。。。求指教方法
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, 192, 114)
$ListView1 = GUICtrlCreateListView("盘符|可用磁盘|磁盘大小|分区格式", 56, 72, 433, 233)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 70)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 120)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 120)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 120)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-9-20 12:32:56 | 显示全部楼层
本帖最后由 xms77 于 2011-9-20 12:34 编辑
$Text = "Partitions|Partition1=C: (NTFS) 30004 MB (19314 MB free)"
$GotSize = StringRegExp($text, '\((\d.*)\)', 1)
MsgBox(0,"",$GotSize[0])

评分

参与人数 1金钱 +40 收起 理由
xyhqqaa + 40 谢谢。。真的很感谢。。。大哥。。谢谢

查看全部评分

发表于 2011-9-20 13:37:05 | 显示全部楼层
Local $Str = _
                '[Summary]' & @CRLF & _
                'Partitions|Partition1=C: (NTFS) 30004 MB (19314 MB free)' & @CRLF & _
                'Partitions|Partition2=D: (NTFS) 25603 MB (24223 MB free)' & @CRLF & _
                'Partitions|Partition3=E: (NTFS) 230000 MB (87171 MB free)' & @CRLF & _
                'Partitions|Partition4=F: (NTFS) 216932 MB (160868 MB free)' & @CRLF & _
                'Partitions|Partition5=G: (NTFS) 226314 MB (151415 MB free)' & @CRLF & _
                'Partitions|Partition6=H: (NTFS) 225019 MB (36250 MB free)' & @CRLF & _
                'Partitions|Partition7=X: (NTFS) 112639 MB (2014 MB free)' & @CRLF & _
                'Partitions|Total Size=1041.5 GB (470.0 GB free)' & @CRLF
Local $Test = StringRegExp($Str, '(.):\h\((.+?)\)\h([^(]+)\h\((.+?)\hfree', 3)

#include <ListViewConstants.au3>

GUICreate('Form1', 623, 449)
$ListView = GUICtrlCreateListView('盘符|可用磁盘|磁盘大小|分区格式', 56, 72, 433, 233)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 70)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 120)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 120)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 120)
For $i = 0 To UBound($Test) - 1 Step 4
        GUICtrlCreateListViewItem($Test[$i] & '|' & $Test[$i + 3] & '|' & $Test[$i + 2] & '|' & $Test[$i + 1], $ListView)
Next

GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
        EndSwitch
WEnd

评分

参与人数 1金钱 +40 收起 理由
xyhqqaa + 40

查看全部评分

 楼主| 发表于 2011-9-20 14:01:12 | 显示全部楼层
回复 3# afan
A饭,您就是一个神。俺知道您一定会出现。没想到真的出现了。。。。。爱您不容易,爱您藏心底。新手很感谢你,虽然现在还看不太懂您写的意思,但俺会努力的,知道伸手不好。。但我以后有能力的话也像您帮助有需要的人

评分

参与人数 1金钱 +50 收起 理由
afan + 50 ^ *

查看全部评分

发表于 2011-9-20 14:23:42 | 显示全部楼层
本帖最后由 gzh888666 于 2011-9-20 14:42 编辑

回复 3# afan
afan太厉害了!又有点收获!
我弄的不好!=(.:?)\h\((.+?)\)\h(.+?\h.+?)\h\((.+?\h.+?)\hfree\)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 19:49 , Processed in 0.096347 second(s), 31 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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