chenlu_ling 发表于 2011-3-15 20:17:40

请问几个正则表达式的写法[已解决]

本帖最后由 chenlu_ling 于 2011-3-16 19:51 编辑


Local $theArray = ["0","1","10","01","000","001","010","011","110","111"]
Local $a = "0"
Local $b = "1"
;请问以下三个问题如何实现,正则表达式怎么写?
;问题一:找出$theArray中首字符为$a的所有值
;问题二:找出$theArray中最后一个字符为$b的所有值
;问题三:找出$theArray中首字符为$a并且最后一个字符为$b的所有值

;当然循环去取值进行比较可以实现,不过我想用正则表达式直接比较出来。。。不知道能不能实现多谢三楼 3mile代码很简洁
也谢谢二楼的 easied   你写的正则表达式也达到了预期效果

easied 发表于 2011-3-15 20:51:29

学习正则,你这问题的核心我就当习题做了.你就帮我批改一下吧{:face (411):}
Local $theArray = ["0","1","10","01","000","001","010","011","110","111"]
Local $a = "0"
Local $b = "1"

For $i = 0 To UBound($theArray) - 1 Step 1
        If StringRegExp($theArray[$i], '^' & $a & '.*' & $b & '$', 0) Then
                MsgBox(4096, $i, $theArray[$i] & " 是字母是$a尾字母是$b的值")
        Else
                If StringRegExp($theArray[$i], '^' & $a, 0) Then MsgBox(4096, $i, $theArray[$i] & " 是首字母是$a的值")
                If StringRegExp($theArray[$i], $b & '$', 0) Then MsgBox(4096, $i, $theArray[$i] & " 是尾字母是$b的值")
        EndIf
Next

3mile 发表于 2011-3-16 11:45:20

#include <array.au3>
Local $theArray = ["0","1","10","01","000","001","010","011","110","111",'01101']
local $a='0'
local $b='1'
$str=_ArrayToString($theArray)

$first=StringRegExp($str,"\b"&$a&"\d*",3)
_arraydisplay($first)

$end=StringRegExp($str,"\d*"&$b&"\b",3)
_ArrayDisplay($end)

$first_end=StringRegExp($str,"\b"&$a&"\d*"&$b&"\b",3)
_arraydisplay($first_end)

jackey009 发表于 2011-3-16 13:40:58

回复 3# 3mile

WinActivate("http://10.60.65.99/sm/gaia.main.d - Windows Internet Explorer","")
WinActive("http://10.60.65.99/sm/gaia.main.d - Windows Internet Explorer","")
sleep(1000)
MouseClick("left", 1018,265,1,10)
sleep(1000)
MouseClick("left", 1036,351,1,10)
sleep(1000)
MouseClick("left", 291,186,1,10)
sleep(6000)
MouseClick("left", 218,157,1,10)
sleep(1000)
send("{ENTER}")
sleep(2000)
send("{TAB}")
sleep(2000)
send("{TAB}")
sleep(2000)
send("{ENTER}")
sleep(1000)

chenlu_ling 发表于 2011-3-16 19:48:10

回复 2# easied

谢了,正则表达式达到了效果
页: [1]
查看完整版本: 请问几个正则表达式的写法[已解决]