xymc 发表于 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)
EndIf
这样能提取到城市为 city":"珠海市","cityCode可是我只想要"珠海市"
自己不懂正则,所以请教下大家怎么样可以只提取“珠海市”

afan 发表于 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), '其中元素为: ' & $aSRE)

fang5072546 发表于 2018-4-1 10:57:48

牛人.借楼问个小白问题.
假设有字符
ab
abc
abcd
如果我只想要提取字符ab,abcd,除了\wb(?=[^c])|\w{3}(?=d).   这个以外,还有别的方案吗?
页: [1]
查看完整版本: 请教正则提取字符串(已解决)