找回密码
 加入
搜索
查看: 1812|回复: 2

[效率算法] 请教正则提取字符串(已解决)

[复制链接]
发表于 2018-3-31 19:58:24 | 显示全部楼层 |阅读模式
本帖最后由 xymc 于 2018-4-3 22:34 编辑

if(window.IPCallBack) {IPCallBack({"ip":"14.125.60.161","pro":"广东省","proCode":"440000","city":"珠海市","cityCode":"440400","region":"","regionCode":"0","addr":"广东省珠海市 电信","regionNames":"","err":""});}



$txt = "if(window.IPCallBack) {IPCallBack({"ip":"14.125.60.161","pro":"广东省","proCode":"440000","city":"珠海市","cityCode":"440400","region":"","regionCode":"0","addr":"广东省珠海市 电信","regionNames":"","err":""});}"
$asResult = StringRegExp($txt,'\bcity\b.*\bcityCode\b',1)
If @error = 0 Then
       MsgBox(0, "结果", $asResult[0])
EndIf
这样能提取到城市为 city":"珠海市","cityCode  可是我只想要"珠海市"
自己不懂正则,所以请教下大家怎么样可以只提取“珠海市”
发表于 2018-3-31 21:49:35 | 显示全部楼层
Local $sSource = 'if(window.IPCallBack) {IPCallBack({"ip":"14.125.60.161","pro":"广东省","proCode":"440000","city":"珠海市","cityCode":"440400","region":"","regionCode":"0","addr":"广东省珠海市 电信","regionNames":"","err":""});}'
;~MsgBox(0, '源字符串', $sSource)
Local $aSRE = StringRegExp($sSource, 'city":"([^"]+)', 1)
If Not @Error Then MsgBox(0, '匹配数量: ' & UBound($aSRE), '其中[0]元素为: ' & $aSRE[0])
发表于 2018-4-1 10:57:48 | 显示全部楼层
牛人.借楼问个小白问题.
假设有字符
ab
abc
abcd
如果我只想要提取字符ab,abcd,除了\wb(?=[^c])|\w{3}(?=d).   这个以外,还有别的方案吗?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-24 02:46 , Processed in 0.082903 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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