找回密码
 加入
搜索
查看: 1668|回复: 4

[网络通信] 如何用正则提取快递信息(已解决)

[复制链接]
发表于 2018-10-25 22:10:15 | 显示全部楼层 |阅读模式
本帖最后由 xymc 于 2018-10-25 23:24 编辑

{"message":"ok","status":"1","state":"3","data":[{"time":"2018-10-20 10:11:31","context":"订单已由本人签收,感谢您在京东购物,欢迎您再次光临!"},{"time":"2018-10-20 08:16:35","context":"配送员开始配送,请您准备收货,配送员,海龙,手机号,1770xxxx644"},{"time":"2018-10-20 07:32:27","context":"货物已分配,等待配送"},{"time":"2018-10-20 07:32:26","context":"货物已到达【中山坦洲站】"},{"time":"2018-10-20 05:41:06","context":"货物已完成分拣,离开【中山分拨中心】"},{"time":"2018-10-20 02:44:38","context":"货物已到达【中山分拨中心】"},{"time":"2018-10-20 02:04:09","context":"货物已交付京东物流"}]}


如何用正则提取物流信息格式如下
2018-10-20 10:11:31 订单已由本人签收,感谢您在京东购物,欢迎您再次光临!
2018-10-20 08:16:35 配送员开始配送,请您准备收货,配送员,海龙,手机号,1770xxxx644

非常感谢下面2位老大的指导,下面是完整代码
 Local $txt = '{"message":"ok","status":"1","state":"3","data":[{"time":"2018-10-20 10:11:31","context":"订单已由本人签收,感谢您在京东购物,欢迎您再次光临!"},{"time":"2018-10-20 08:16:35","context":"配送员开始配送,请您准备收货,配送员,海龙,手机号,1770xxxx644"},{"time":"2018-10-20 07:32:27","context":"货物已分配,等待配送"},{"time":"2018-10-20 07:32:26","context":"货物已到达【中山坦洲站】"},{"time":"2018-10-20 05:41:06","context":"货物已完成分拣,离开【中山分拨中心】"},{"time":"2018-10-20 02:44:38","context":"货物已到达【中山分拨中心】"},{"time":"2018-10-20 02:04:09","context":"货物已交付京东物流"}]}'
        $data = StringRegExp($txt,'(?i)"time":"(.+?)","context":"(.+?)"',3)
        ;MsgBox(0, "", $data[0]&$data[1])
        ;MsgBox(0,"",UBound($data)-1)
        Local $txt_data
        Local $nub = 0
        For $i = 0 To UBound($data) - 1
                ;MsgBox(4096, "正则测试" & $i, $data[$i])
                $nub = $nub+1
                Local $tat_a=$data[$i]
                ;MsgBox(4096, "正则测试" & $i, $tat_a)
                If $nub =2 Then
                        Local $nub = 0
                        $txt_data=$txt_data&$tat_a&@CRLF
                Else
                        $txt_data=$txt_data&$tat_a
                EndIf
        Next
                MsgBox(4096, "正则测试",$txt_data)



发表于 2018-10-25 22:16:41 | 显示全部楼层
(?i)"time":"(.+?)","context":"(.+?)"

 楼主| 发表于 2018-10-25 22:38:04 | 显示全部楼层
zghwelcome 发表于 2018-10-25 22:16
(?i)"time":"(.+?)","context":"(.+?)"

        Local $txt = '{"message":"ok","status":"1","state":"3","data":[{"time":"2018-10-20 10:11:31","context":"订单已由本人签收,感谢您在京东购物,欢迎您再次光临!"},{"time":"2018-10-20 08:16:35","context":"配送员开始配送,请您准备收货,配送员,海龙,手机号,1770xxxx644"},{"time":"2018-10-20 07:32:27","context":"货物已分配,等待配送"},{"time":"2018-10-20 07:32:26","context":"货物已到达【中山坦洲站】"},{"time":"2018-10-20 05:41:06","context":"货物已完成分拣,离开【中山分拨中心】"},{"time":"2018-10-20 02:44:38","context":"货物已到达【中山分拨中心】"},{"time":"2018-10-20 02:04:09","context":"货物已交付京东物流"}]}'
       
        $data = StringRegExp($txt,'(?i)"time":"(.+?)","context":"(.+?)"',1)
        MsgBox(0, "", $data[0]&$data[1])

只提取到第一条物流信息
有没有办法提取完?
发表于 2018-10-25 22:46:00 | 显示全部楼层
函数参数 3 1
 楼主| 发表于 2018-10-25 23:25:20 | 显示全部楼层

谢谢,已解决
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-24 00:18 , Processed in 0.069689 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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