elexy 发表于 2015-1-16 12:11:28

【已解决】比较复杂的文本,请教正则高手

本帖最后由 elexy 于 2015-1-16 13:31 编辑

$str='{"classid":"58","total":2334,"page":"1","data":[{"rid":"dc49bcd5a8c251ea99b3fda4c1e66d1f","subject":"【娱乐高高手】!姚贝娜近况:仍昏迷未暴瘦 孙俪等祈福","time":"1421304674","cid":"58"},{"rid":"8f2e6d498c60e0d146b480bfa5e3d384","subject":"【娱乐周刊】专访阮经天:周冬雨正面背面看起来一样平","time":"1421214609","cid":"58"},{"rid":"cec6e434410f155ce7d6d80df5ad6c4f","subject":"【娱乐高高手】2014年大翻身!Baby成《跑男》最大赢家","time":"1421213676","cid":"58"},{"rid":"71f1f366405630f6b3b66bf1d413deee","subject":"【娱乐周刊】《歌手3》迎首位踢馆歌手 陈洁仪惊艳返场","time":"1421201360","cid":"58"},{"rid":"e0e256c2a4e35430835f2dfbe404c069","subject":"【娱乐高高手】 谢霆锋经纪人霍汶希:“锋菲”没有结婚打算","time":"1421131195","cid":"58"},{"rid":"ddfc534bde4a0add289087dfa1291dec","subject":"【娱乐周刊】林俊杰包庇好友出轨代认小三 网友赞超义气","time":"1421042887","cid":"58"},{"rid":"ba4d0f851a7328804774b576b931d80a","subject":"【娱乐高高手】34岁台女星隋棠与男友闪婚 前情敌王心凌祝福","time":"1421027808","cid":"58"},{"rid":"4a9283738f98eba2d5c3442fea4eb62d","subject":"【娱乐周刊】 王诗龄为拍电影狂奔又落水 张家辉赞其聪明","time":"1420770472","cid":"58"},{"rid":"ba9ae002db9707a84b7b989a194a84a0","subject":"【娱乐周刊】陈坤携新书亮相 现场作画自称“美男子”","time":"1420768807","cid":"58"},{"rid":"0b76c1b8a74a4a8fc4d9f7ff9165de37","subject":"【娱乐高高手】 《新年行动》曝女神版预告 性感水蛇腰勾魂摄魄","time":"1420613086","cid":"58"}'
$cen = StringRegExp($str, '', 3)
msgbox(64,$cen,$cen)需求:挑出所有【娱乐高高手】栏目包括 标题 和 前面的rid,不要【娱乐周刊】栏目的标题和rid。

范例:$cen = dc49bcd5a8c251ea99b3fda4c1e66d1f   $cen = 【娱乐高高手】!姚贝娜近况:仍昏迷未暴瘦 孙俪等祈福   

$cen = cec6e434410f155ce7d6d80df5ad6c4f$cen = 【娱乐高高手】2014年大翻身!Baby成《跑男》最大赢家

....。。。。以此类推

afan 发表于 2015-1-16 12:45:59

(?i)rid":"([^"]+)[^【]+?(【娱乐高高手】[^"]+)

半芯竹 发表于 2015-1-16 13:29:15

本帖最后由 半芯竹 于 2015-1-16 13:33 编辑


#include <Array.au3>
Local $file = FileOpen(@ScriptDir&"\1.txt", 0)
If $file = -1 Then Exit
Local $chars = FileRead($file)
If @error = -1 Then Exit
Local $res = StringRegExp($chars,"\w{20,}(?=\S\,\S\w+\S\:\S【娱乐高高手)|【娱乐高高手.*?(?=\S\,)",3)
If Not @error Then _arraydisplay($res,'test')
FileClose($file)

随便弄了一下,看是不是你想要的效果

elexy 发表于 2015-1-16 13:31:21

谢谢afan,半芯竹,二楼解决问题,三楼可能没看清题目,把不需要的娱乐周刊一起抓进来了

半芯竹 发表于 2015-1-16 13:34:05

回复 4# elexy


    看错了,现在改过来了。。

半芯竹 发表于 2015-1-16 13:34:57

回复 4# elexy


二楼解决问题??我怎么调试不出来。。。。
页: [1]
查看完整版本: 【已解决】比较复杂的文本,请教正则高手