如何用正则提取快递信息(已解决)
本帖最后由 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&$data)
;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)
(?i)"time":"(.+?)","context":"(.+?)"
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&$data)
只提取到第一条物流信息
有没有办法提取完? 函数参数 3 1 绿色风 发表于 2018-10-25 22:46
函数参数 3 1
谢谢,已解决
页:
[1]