[已解决]关于正则获取字段中括号的值
本帖最后由 xyhqqaa 于 2011-9-20 14:03 编辑想用everest获取电脑配置信息。。。在生成的配置文件中有
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
本帖最后由 xms77 于 2011-9-20 12:34 编辑
$Text = "Partitions|Partition1=C: (NTFS) 30004 MB (19314 MB free)"
$GotSize = StringRegExp($text, '\((\d.*)\)', 1)
MsgBox(0,"",$GotSize) Local $Str = _
'' & @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
回复 3# afan
A饭,您就是一个神。俺知道您一定会出现。没想到真的出现了。。。。。爱您不容易,爱您藏心底。新手很感谢你,虽然现在还看不太懂您写的意思,但俺会努力的,知道伸手不好。。但我以后有能力的话也像您帮助有需要的人 本帖最后由 gzh888666 于 2011-9-20 14:42 编辑
回复 3# afan
afan太厉害了!又有点收获!
我弄的不好!=(.:?)\h\((.+?)\)\h(.+?\h.+?)\h\((.+?\h.+?)\hfree\)
页:
[1]