回复 12# CCM
我反复看了你此楼及7楼的内容, 还是弄不清楚你最后要匹配出什么样的结果.
目标文本已知时, 用正则匹配, 一般是直接进行全文匹配, 而不是单行匹配.
如果不能一次性匹配到目标字符, 可以在初次匹配的结果上进行多次正则, 直到获取到目标为止.
#include<array.au3>
Local $txt = _
'已安装打印机清单及预设打印机:' & @CRLF & _
'1. CutePDF Writer, CPW2:' & @CRLF & _
'2. FX ApeosPort-II 7000 PCL 6 (P102), \\printer\p102' & @CRLF & _
'3. HP LaserJet 4350 PCL 6 (P194), \\printer\p194' & @CRLF & _
'4. HP LaserJet P3010 Series PCL 6 (P198), \\printer\p198' & @CRLF & _
'5. Microsoft Office Document Image Writer, Microsoft Document Imaging Writer Port:' & @CRLF & _
'6. Microsoft XPS Document Writer, XPSPort:' & @CRLF & _
'7. PrimoPDF, PrimoPort:' & @CRLF & _
'预设打印机:HP LaserJet 4350 PCL 6 (P194),winspool,Ne04:'
MsgBox(0, '原来文本内容', $txt)
$str = StringRegExp($txt, '.+PDF\h+Writer.+|.+PCL\h+6.+', 3)
_ArrayDisplay($str, '所有匹配内容')
;; 详细处理
If IsArray($str) Then
MsgBox(0, '匹配数量', UBound($str))
For $i = 0 To UBound($str) - 1
If StringInStr($str[$i], '预设打印机') Then
$name = StringRegExp($str[$i], '预设打印机:(\V+)', 1)
If Not @error Then MsgBox(0, '预设打印机', $name[0])
ElseIf StringInStr($str[$i], '(') Then
$name = StringRegExp($str[$i], '\d\.\h*(.+)\h*\(\w+\),\h*(.+)', 3)
If Not @error Then MsgBox(0, '第 ' & $i + 1 & ' 台打印机信息', '打印机名字:' & @TAB & $name[0] & @CR & '其共享名:' & @TAB & $name[1])
Else
$name = StringRegExp($str[$i], '\d\.\h*([^\(\)]+)', 3)
If Not @error Then MsgBox(0, '第 ' & $i + 1 & ' 台打印机名: ', $name[0])
EndIf
Next
EndIf
|