auto 发表于 2022-3-21 09:31:09

【已解决】请教一个数据提取正则编写

本帖最后由 auto 于 2022-3-22 12:49 编辑

#include <Array.au3>
Local $sSource = ''
$sSource &= '<div class=ht><B><a href="/beijing/">北京地名</a></b></div><div id=list110><a href="/beijing/dongchengqu.html">东城区</a></div><div id=list110><a href="/beijing/xichengqu.html">西城区</a></div><div id=list110><a href="/beijing/chaoyangqu.html">朝阳区</a></div><div id=list110><a href="/beijing/fengtaiqu.html">丰台区</a></div><div id=list110><a href="/beijing/shijingshanqu.html">石景山区</a></div><div id=list110><a href="/beijing/haidianqu.html">海淀区</a></div><div id=list110><a href="/beijing/mentougouqu.html">门头沟区</a></div><div id=list110><a href="/beijing/fangshanqu.html">房山区</a></div><div id=list110><a href="/beijing/shunyiqu.html">顺义区</a></div><div id=list110><a href="/beijing/daxingqu.html">大兴区</a></div><div id=list110><a href="/beijing/pingguqu.html">平谷区</a></div><div id=list110><a href="/beijing/yanqingxian.html">延庆县</a></div><div id=list110><a href="/beijing/miyun.html">密云县</a></div><div id=list110><a href="/beijing/huairou.html">怀柔区</a></div><div id=list110><a href="/beijing/changping.html">昌平区</a><'
$sSource &= '/div><div id=list110><a href="/beijing/tongzhouqu.html">通州区</a></div><div class=ht><B><a href="/tianjin/">天津地名</a></b></div><div id=list110><a href="/tianjin/hepingqu.html">和平区</a></div><div id=list110><a href="/tianjin/hedongqu.html">河东区</a></div><div id=list110><a href="/tianjin/hexiqu.html">河西区</a></div><div id=list110><a href="/tianjin/nankaiqu.html">南开区</a></div><div id=list110><a href="/tianjin/hebeiqu.html">河北区</a></div><div id=list110><a href="/tianjin/hongqiaoqu.html">红桥区</a></div><div id=list110><a href="/tianjin/tangguqu.html">滨海新区</a></div><div id=list110><a href="/tianjin/dongliqu.html">东丽区</a></div><div id=list110><a href="/tianjin/xiqingqu.html">西青区</a></div><div id=list110><a href="/tianjin/jinnanqu.html">津南区</a></div><div id=list110><a href="/tianjin/beichenqu.html">北辰区</a></div><div id=list110><a href="/tianjin/wuqingqu.html">武清区</a></div><div id=list110><a href="/tianjin/baoqu.html">宝坻区</a></div><div id=list110><a href="/tianjin/ninghexian.html">宁河区</a></div><div id='
$sSource &= 'list110><a href="/tianjin/jixian.html">蓟县</a></div><div id=list110><a href="/tianjin/jinghai.html">静海区</a></div><div class=ht><B><a href="/hebei/">河北地名</a></b></div><div id=list110><a href="/hebei/handan.html">邯郸</a></div><div id=list110><a href="/hebei/xingtai.html">邢台</a></div><div id=list110><a href="/hebei/hengshui.html">衡水</a></div><div id=list110><a href="/hebei/cangzhou.html">沧州</a></div><div id=list110><a href="/hebei/baoding.html">保定</a></div><div id=list110><a href="/hebei/zhangjiakou.html">张家口</a></div><div id=list110><a href="/hebei/langfang.html">廊坊</a></div><div id=list110><a href="/hebei/tangshanshi.html">唐山市</a></div><div id=list110><a href="/hebei/shijiazhuang.html">石家庄</a></div><div id=list110><a href="/hebei/chengde.html">承德</a></div><div id=list110><a href="/hebei/qinhuangdao.html">秦皇岛</a></div>' & @CRLF
$sSource &= '                ' & @CRLF
$sSource &= '                <div class=ht><B><a href="/shanxisheng/">山西地名</a></b></div><div id=list110><a href="/shanxisheng/yuncheng.html">运城</a></div><div id=list110><a href="/shanxisheng/jincheng.html">晋城</a></div><div id=list110><a href="/shanxisheng/changzhi.html">长治</a></div><div id=list110><a href="/shanxisheng/linfen.html">临汾</a></div><div id=list110><a href="/shanxisheng/jinzhong.html">晋中</a></div><div id=list110><a href="/shanxisheng/lvliang.html">吕梁</a></div><div id=list110><a href="/shanxisheng/yangquan.html">阳泉</a></div><div id=list110><a href="/shanxisheng/xinzhou.html">忻州</a></div><div id=list110><a href="/shanxisheng/shuozhou.html">朔州</a></div><div id=list110><a href="/shanxisheng/datong.html">大同</a></div><div id=list110><a href="/shanxisheng/taiyuan.html">太原</a></div><div class=ht><B><a href="/neimenggu/">内蒙古地名</a></b></div><div id=list110><a href="/neimenggu/xinganmeng.html">兴安盟</a></div><div id=list110><a href="/neimenggu/wuhai.html">乌海市</a></div><div id=list110><a href="/neimenggu/eerduosi.h'
$sSource &= 'tml">鄂尔多斯</a></div><div id=list110><a href="/neimenggu/wulanchabu.html">乌兰察布</a></div><div id=list110><a href="/neimenggu/chifeng.html">赤峰市</a></div><div id=list110><a href="/neimenggu/tongliao.html">通辽市</a></div><div id=list110><a href="/neimenggu/xilinguolemeng.html">锡林郭勒盟</a></div><div id=list110><a href="/neimenggu/bayannaoer.html">巴彦淖尔</a></div><div id=list110><a href="/neimenggu/alashanmeng.html">阿拉善盟</a></div><div id=list110><a href="/neimenggu/baotou.html">包头市</a></div><div id=list110><a href="/neimenggu/hulunbeier.html">呼伦贝尔</a></div><div id=list110><a href="/neimenggu/huhehaote.html">呼和浩特</a></div><div class=ht><B><a href="/liaoning/">辽宁地名</a></b></div><div id=list110><a href="/liaoning/chaoyang.html">朝阳</a></div><div id=list110><a href="/liaoning/liaoyang.html">辽阳</a></div><div id=list110><a href="/liaoning/panjin.html">盘锦</a></div><div id=list110><a href="/liaoning/yingkou.html">营口</a></div><div id=list110><a href="/liaoning/anshan.html">鞍山</a></div><div id=list110><a href='
$sSource &= '"/liaoning/jinzhou.html">锦州</a></div><div id=list110><a href="/liaoning/fuxin.html">阜新</a></div><div id=list110><a href="/liaoning/fushun.html">抚顺</a></div><div id=list110><a href="/liaoning/tieling.html">铁岭</a></div><div id=list110><a href="/liaoning/benxi.html">本溪</a></div><div id=list110><a href="/liaoning/huludao.html">葫芦岛</a></div><div id=list110><a href="/liaoning/dandong.html">丹东</a></div><div id=list110><a href="/liaoning/dalian.html">大连</a></div><div id=list110><a href="/liaoning/shenyang.html">沈阳</a></div><div class=ht><B><a href="/jilin/">吉林地名</a></b></div><div id=list110><a href="/jilin/yanbian.html">延边州</a></div><div id=list110><a href="/jilin/liaoyuan.html">辽源市</a></div><div id=list110><a href="/jilin/siping.html">四平市</a></div><div id=list110><a href="/jilin/songyuan.html">松原市</a></div><div id=list110><a href="/jilin/baicheng.html">白城市</a></div><div id=list110><a href="/jilin/jilinshi.html">吉林市</a></div><div id=list110><a href="/jilin/baishan.html">白山市</a></div><div id=li'
$sSource &= 'st110><a href="/jilin/tonghua.html">通化市</a></div><div id=list110><a href="/jilin/changchun.html">长春市</a></div><div class=ht><B><a href="/heilongjiang/">黑龙江地名</a></b></div><div id=list110><a href="/heilongjiang/qitaihe.html">七台河</a></div><div id=list110><a href="/heilongjiang/daxinganling.html">大兴安岭</a></div><div id=list110><a href="/heilongjiang/mudanjiang.html">牡丹江</a></div><div id=list110><a href="/heilongjiang/jixi.html">鸡西</a></div><div id=list110><a href="/heilongjiang/shuangyashan.html">双鸭山</a></div><div id=list110><a href="/heilongjiang/jiamusi.html">佳木斯</a></div><div id=list110><a href="/heilongjiang/hegang.html">鹤岗</a></div><div id=list110><a href="/heilongjiang/yichun.html">伊春</a></div><div id=list110><a href="/heilongjiang/suihua.html">绥化</a></div><div id=list110><a href="/heilongjiang/daqing.html">大庆</a></div><div id=list110><a href="/heilongjiang/qiqihaer.html">齐齐哈尔</a></div><div id=list110><a href="/heilongjiang/heihe.html">黑河</a></div><div id=list110><a href="/heilongjia'
$sSource &= 'ng/haerbin.html">哈尔滨</a></div>' & @CRLF
$sSource &= '          </div></td>' & @CRLF
;~ MsgBox(0, '源字符串', $sSource)
Local $aSRE = StringRegExp($sSource, '<a href="/(.+?)/">(.+?地名)</a>', 3)
If Not @Error Then MsgBox(0, '匹配数量: ' & UBound($aSRE), '其中元素为: ' & $aSRE)
_ArrayDisplay($aSRE, UBound($aSRE))


实际上我想要结果是
beijing
北京地名
tianjin
天津地名
。。。。

zghwelcome 发表于 2022-3-21 10:54:28

<a href="/([^"]+)/">(.+?地名)</a>

auto 发表于 2022-3-22 09:28:03

zghwelcome 发表于 2022-3-21 10:54


[^"] 为啥要这么写,是不包括双号括的吗?

zghwelcome 发表于 2022-3-22 09:59:07

排除双引号
页: [1]
查看完整版本: 【已解决】请教一个数据提取正则编写