找回密码
 加入
搜索
查看: 6451|回复: 14

[AU3基础] 如何正则出最后一个字符串。(有例子)[已解决]

 火.. [复制链接]
发表于 2012-9-29 03:28:12 | 显示全部楼层 |阅读模式
本帖最后由 黑色袜子 于 2012-9-29 11:23 编辑
$str=test【123】test[321.]test(456】end
怎样正则出(456】?
test123......这个循环次数未知。
(456】是字符串。长度未知。

最终的目的就是提取靠近end的字符串


4L代码
#include <Array.au3>
$str="test【123】test[321.]test(456】end"
$array=StringRegExp($str,'test.([^(test)]+).end',3)
_ArrayDisplay($array)
6L代码
$str="test【123】test[321.]test(456】end"
$arr=StringRegExp($str,"test(.*?)(?=test|end|$)",3)
If Not @error Then MsgBox(0,"",$arr[ubound($arr)-1])
发表于 2012-9-29 07:25:44 | 显示全部楼层
楼主对问题描述很不清晰呀, 又是靠近,又是长度未知...
请问:  test(456】 不可以看作靠近end的字符串?
那么 [321.]test(456】?     6】???
发表于 2012-9-29 07:32:50 | 显示全部楼层
昨晚还没有搞定?
我在群里不是叫你上传TXT文件了吗?
发表于 2012-9-29 09:27:20 | 显示全部楼层
本帖最后由 shqf 于 2012-9-29 09:28 编辑

#include <Array.au3>
$str="test【123】test[321.]test(456】end"
$array=StringRegExp($str,'test.([^(test)]+).end',3)
_ArrayDisplay($array)

评分

参与人数 1金钱 +20 收起 理由
黑色袜子 + 20 好。谢谢

查看全部评分

 楼主| 发表于 2012-9-29 11:13:59 | 显示全部楼层
昨晚还没有搞定?
我在群里不是叫你上传TXT文件了吗?
hzxymkb 发表于 2012-9-29 07:32



    额。我没看到。估计那个时候睡觉了。
发表于 2012-9-29 11:14:28 | 显示全部楼层
$str="test【123】test[321.]test(456】end"
$arr=StringRegExp($str,"test(.*?)(?=test|end|$)",3)
If Not @error Then MsgBox(0,"",$arr[ubound($arr)-1])
试下

评分

参与人数 1金钱 +20 收起 理由
黑色袜子 + 20 谢谢。

查看全部评分

 楼主| 发表于 2012-9-29 11:22:34 | 显示全部楼层
突然发现4L的代码。没把(和】正则出来
 楼主| 发表于 2012-9-29 12:05:24 | 显示全部楼层
试下
kevinch 发表于 2012-9-29 11:14



    经过测试。你的代码。无关最后的end 只要有test就会提取出来。比如
$str="test【123】test[321.]test(456】endtest【copy】"
这样。【copy】也会出来。
 楼主| 发表于 2012-9-29 12:26:53 | 显示全部楼层
回复 2# user3000


    我的意思是test(.*)end的字符串。要取的是靠近end的。不好意思。没表达清楚。
发表于 2012-9-29 17:58:14 | 显示全部楼层
回复 9# 黑色袜子

理解了. 4楼稍稍修改就可以了.

'test([^(test)]+)end'
发表于 2012-9-29 19:53:41 | 显示全部楼层
$str="test【123】test[321.]test(456】end"
$arr=StringRegExp($str,"test(.*?)(?=end)",3)
If Not @error Then MsgBox(0,"",$arr[ubound($arr)-1])
那就是这样了,所谓最后一个,实在让人疑惑
发表于 2012-9-29 21:57:41 | 显示全部楼层
StringRegExp($str,'.*test(.*?)end',3)

评分

参与人数 1金钱 +20 收起 理由
黑色袜子 + 20 谢谢

查看全部评分

发表于 2012-9-29 21:57:52 | 显示全部楼层
本帖最后由 love5173 于 2012-9-29 22:12 编辑
StringRegExp($str,'.*test(.*?)end',3)
这个不是灌水的,网络卡点了两下
发表于 2012-10-3 12:47:23 | 显示全部楼层
看描述,还是有诱惑力的。学习先
发表于 2012-10-4 01:36:12 | 显示全部楼层
看看....看能不得出来不
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-14 20:23 , Processed in 0.112210 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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