找回密码
 加入
搜索
查看: 2301|回复: 7

[AU3基础] 文本 数组 正则问题[已解决]

  [复制链接]
发表于 2010-8-18 19:46:06 | 显示全部楼层 |阅读模式
本帖最后由 23070205 于 2010-8-18 20:55 编辑

想做个显示器分辨率的软件
得到了一组分辨率数字到文本了,怎么用正则表达式
640        400        8                70
640        400        16                70
640        400        32                70
640        480        4                frequency set in hardware
640        480        8                60
640        480        8                70
640        480        8                72
640        480        8                75
640        480        16                60
640        480        16                70
640        480        16                72
640        480        16                75
640        480        32                60
640        480        32                70
640        480        32                72
640        480        32                75
720        480        8                60
720        480        16                60
720        480        32                60
720        576        8                60
720        576        16                60
720        576        32                60
800        600        4                frequency set in hardware
800        600        8                56
800        600        8                60
800        600        8                70
800        600        8                72
800        600        8                75
800        600        16                56
800        600        16                60
800        600        16                70
800        600        16                72
800        600        16                75
800        600        32                56
800        600        32                60
800        600        32                70
800        600        32                72
800        600        32                75
1024        768        8                60
1024        768        8                70
1024        768        8                72
1024        768        8                75
1024        768        16                60
1024        768        16                70
1024        768        16                72
1024        768        16                75
1024        768        32                60
1024        768        32                60
1024        768        32                70
1024        768        32                70
1024        768        32                72
1024        768        32                72
1024        768        32                75
1024        768        32                75
1280        720        8                60
1280        720        16                60
1280        720        32                60
1280        768        8                60
1280        768        8                70
1280        768        8                72
1280        768        8                75
1280        768        16                60
1280        768        16                70
1280        768        16                72
1280        768        16                75
1280        768        32                60
1280        768        32                70
1280        768        32                72
1280        768        32                75
1360        768        8                60
1360        768        16                60
1360        768        32                60
1366        768        8                59
1366        768        8                60
1366        768        16                59
1366        768        16                60
1366        768        32                59
1366        768        32                60


我想到的正则是
\d{3,4}\h+\d{3,4}\h+\d{1,2}\h+\d\d
就是还是不行,指教
列出来的这个正则要用到combo中
 楼主| 发表于 2010-8-18 19:59:24 | 显示全部楼层
以下为测试用的gui
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 325, 92, -1,-1)
$Combo1 = GUICtrlCreateCombo("Combo1", 16, 32, 177, 25)
$Button1 = GUICtrlCreateButton("Button1", 224, 24, 65, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        file()
        EndSwitch
WEnd

Func file()
        Local $Result
        $Text = FileRead(@DesktopDir & '\1.txt') ;将需要匹配的字符串保存在脚本同目录下 Text.txt 文件里
        MsgBox(0, '原字符串', $Text)

        $Reg = StringRegExpReplace($Text, '\d{3,4}\h+\d{3,4}\h+\d{1,2}\h+\d\d', 3)

        For $i = 0 To UBound($Reg) - 1
                $Result &= $Reg[$i] & @CRLF
        Next

        MsgBox(0, '匹配结果', $Result)
        FileWrite(@DesktopDir & '\匹配结果.txt', $Result) ;匹配结果将会存放在脚本同目录下 匹配结果.txt 文件里
EndFunc   ;==>file
发表于 2010-8-18 20:03:41 | 显示全部楼层
想得到什么都不知道…
 楼主| 发表于 2010-8-18 20:05:17 | 显示全部楼层
想提取 这些数组到combo中
发表于 2010-8-18 20:12:06 | 显示全部楼层
容易理解点的
'(\d+)\h+(\d+)\h+(\d+)\h+([^\r\n]+)'
发表于 2010-8-18 20:13:23 | 显示全部楼层
是这个意思?
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 325, 92, -1,-1)
$Combo1 = GUICtrlCreateCombo("", 16, 32, 177, 25)
$Button1 = GUICtrlCreateButton("Button1", 224, 24, 65, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        file()
        EndSwitch
WEnd

Func file()
        Local $Result
        $Text = FileRead(@DesktopDir & '\1.txt') ;将需要匹配的字符串保存在脚本同目录下 Text.txt 文件里
        MsgBox(0, '原字符串', $Text)

        $Reg = StringRegExp($Text, '\d{3,4}\h+\d{3,4}\h+\d{1,2}\h+\d\d', 3)

        For $i = 0 To UBound($Reg) - 1
                        $r=StringRegExpReplace($Reg[$i],'\h+',' ')                                
            $Result &= $r & '|'
        Next

        MsgBox(0, '匹配结果', $Result)
                GUICtrlSetData($Combo1,$Result)
        ;FileWrite(@DesktopDir & '\匹配结果.txt', $Result) ;匹配结果将会存放在脚本同目录下 匹配结果.txt 文件里
EndFunc   ;==>file

评分

参与人数 1金钱 +10 收起 理由
23070205 + 10 谢谢。真棒

查看全部评分

 楼主| 发表于 2010-8-18 20:18:27 | 显示全部楼层
找到一个,udf中的,好像也可以用

_FileReadToArray
--------------------------------------------------------------------------------

读取一个指定文件到一个数组.


#Include <File.au3>
_FileReadToArray($sFilePath, ByRef $aArray)
 楼主| 发表于 2010-8-18 20:20:48 | 显示全部楼层
6楼老兄谢谢了,就是这个意思,高手
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-3 10:40 , Processed in 0.090850 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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