找回密码
 加入
搜索
查看: 2418|回复: 5

[AU3基础] 问下正则匹配链接和提取问题

[复制链接]
发表于 2009-4-17 21:03:07 | 显示全部楼层 |阅读模式
本帖最后由 lynfr8 于 2010-6-12 02:44 编辑

文本如下:
第一列      第二列                 第三列
1.....
40 Can AutoitX run a complete script or an a3x file? http://www.autoitscript.com/forum/index.php?showtopic=83292
41 Last post by: http://www.autoitscript.com/forum/index.php?showtopic=83292&view=getlastpost
42 3.3.0.0 Unicode Functions http://www.autoitscript.com/forum/index.php?showtopic=89698
43 Last post by: http://www.autoitscript.com/forum/index.php?showtopic=89698&view=getlastpost

条件:
第一列为序号,从1-40
第二列为文章名,如Can AutoitX run a complete script or an a3x file?   和   3.3.0.0 Unicode Functions
第三列为文章链接,如http://www.autoitscript.com/forum/index.php?showtopic=83292
其中链接部分是有规律的,就是showtopic=数字部分不同

目的:
1.删除序列号【StringTrimLeft可以做到】
   删除含有Last post by的整行(如41、43行)
2.通过正则表达式和循环结构连续分别提取40、42行的文章名到$a,提取链接到$b




已解决




$file = FileOpen("2.txt", 0)
If $file = -1 Then
  MsgBox(0, "错误", "不能打开文件.")
  Exit
EndIf
dim $count;
While 1
  $line = FileReadLine($file)
  If @error = -1 Then ExitLoop
  $array = StringSplit($line, " ")
  $count = $count + 1
  dim $title = ""
  dim $name = ""
  dim $link
  for $i = 3 to UBound($array) - 3
   $title = $title & " "  & $array[$i]
   $name = $name & "_" & $array[$i]
  Next
 楼主| 发表于 2009-4-17 21:27:10 | 显示全部楼层
在线等.......
发表于 2009-4-17 22:05:16 | 显示全部楼层
你试试看能不能用
#include<array.au3>
$text='40 Can AutoitX run a complete script or an a3x file? [url]http://www.autoitscript.com/forum/index.php?showtopic=83292'&@CRLF& _
'41 Last post by: [url]http://www.autoitscript.com/forum/index.php?showtopic=83292&view=getlastpost'&@CRLF& _
'42 3.3.0.0 Unicode Functions [url]http://www.autoitscript.com/forum/index.php?showtopic=89698'&@CRLF& _
'43 Last post by: [url]http://www.autoitscript.com/forum/index.php?showtopic=89698&view=getlastpost'
;~ ConsoleWrite($text)
$array=StringRegExp($text,'\d+\s(.+)\s(http.+)',3);stringregexp($text,'\d+ (.+) (http.+)',3)
;~ _ArrayDisplay($array)
For $i=0 To UBound($array)-1 Step 2
        If $array[$i]='Last post by:' Then ContinueLoop
        $a=$array[$i]
        $b=$array[$i+1]
        ConsoleWrite($a&" "&$b)
Next

我试了下可以用,但有点小问题

[ 本帖最后由 cnsnc 于 2009-4-17 22:06 编辑 ]

评分

参与人数 1金钱 +2 收起 理由
lynfr8 + 2 不管怎样谢谢你!

查看全部评分

发表于 2009-4-17 22:32:39 | 显示全部楼层
这个对我高深了!

帮不了你!!
发表于 2009-4-17 23:32:22 | 显示全部楼层
\d+\s+(.*?)\s+(http://www\.autoitscript\.com/forum/index\.php\?showtopic\=\d+)\s*\r

评分

参与人数 1金钱 +1 收起 理由
lynfr8 + 1 谢谢!

查看全部评分

发表于 2009-4-17 23:46:23 | 显示全部楼层
这个可能对你有帮助
<span.*?<a.*?href="([^&]*?\d+)".*?>(.*?)</a>.*\r\n

评分

参与人数 1金钱 +22 收起 理由
lynfr8 + 22

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-10 19:44 , Processed in 0.072964 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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