找回密码
 加入
搜索
查看: 2834|回复: 10

[AU3基础] (已解决)正则匹配多个类似项问题

  [复制链接]
发表于 2016-2-18 16:26:41 | 显示全部楼层 |阅读模式
本帖最后由 qazwsxedc 于 2016-2-19 08:21 编辑

有源字符串:aa<div>test1</div>bb<div>test2</div>cc<div>test3</div>dd,
字符串按同样规律可继续加长,其中aa,bb,cc,dd,test1,test2,test3是变化的,
要求匹配到test2或test3,
请问正则如何写?
发表于 2016-2-18 16:48:32 | 显示全部楼层
怎么能 "test2 或 test3" 呢?要么指定 2 要么指定 3,要么都要,"或"是几个意思…
.+?/div>.+?>(.+?)</div
发表于 2016-2-18 16:54:25 | 显示全部楼层
回复 2# afan


    Afan人才~明察秋毫啊~
>.*?</div>.*?<div>(.*?)</div.*?<div>(.*?)</div
 楼主| 发表于 2016-2-18 17:00:58 | 显示全部楼层
是位置不确定,有时候是test2,有时候是其它位置,如test6,所以不能以<div>test?</div>对的位置判断
发表于 2016-2-18 17:22:29 | 显示全部楼层
是位置不确定,有时候是test2,有时候是其它位置,如test6,所以不能以test?对的位置判断
qazwsxedc 发表于 2016-2-18 17:00



    所以 你连自己都不确定是哪个? _ _||   基本的匹配需求特征都不描述  怎么帮?
 楼主| 发表于 2016-2-18 17:26:55 | 显示全部楼层
是的,第一次忘了,匹配时知道<div>test?</div>xx,xx是知道的
发表于 2016-2-18 17:55:51 | 显示全部楼层
Local $sSource = 'aa<div>test1</div>bb<div>test2</div>xx<div>test3</div>dd'
;~MsgBox(0, '源字符串', $sSource)
Local $sK = 'xx'
Local $aSRE = StringRegExp($sSource, '>([^<]+?)</div>' & $sK, 3)
If Not @Error Then MsgBox(0, '匹配数量: ' & UBound($aSRE), '其中[0]元素为: ' & $aSRE[0])
 楼主| 发表于 2016-2-18 19:03:27 | 显示全部楼层
谢谢!问题解决
另外,突然想到如上同样结构的字符串,如果<div>test?</div>xx改为cat This is an example! end of cat
,[^<]该如何修改?
发表于 2016-2-18 19:06:30 | 显示全部楼层
afan果然大神耶
发表于 2016-2-18 19:48:05 | 显示全部楼层
谢谢!问题解决
另外,突然想到如上同样结构的字符串,如果test?xx改为cat This is an example! end of ca ...
qazwsxedc 发表于 2016-2-18 19:03



    “如果<div>test?</div>xx改为cat This is an example! end of cat” 你这样整句改 毛都匹配不到
发表于 2016-2-25 22:44:34 | 显示全部楼层
回复 10# afan


   就喜欢A大不经意的幽默~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 02:15 , Processed in 0.094485 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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