找回密码
 加入
搜索
查看: 5171|回复: 9

[AU3基础] 已解决 正则表达式如何按词匹配?

  [复制链接]
发表于 2012-3-31 11:14:37 | 显示全部楼层 |阅读模式
本帖最后由 Qokelate 于 2012-3-31 12:36 编辑

如何正则替换掉所有 不以 .MP3 或 .xml 结尾的行?
C:\Users\Administrator\AppData\Roaming\Trine2\options.txt
C:\Users\Administrator\AppData\Roaming\TTPlayer\cache
C:\Users\Administrator\AppData\Roaming\VMware\inventory.vmls
C:\Users\Administrator\AppData\Roaming\VMware\preferences.ini
C:\Users\Administrator\AppData\Roaming\Winamp\auth.ini
C:\Users\Administrator\AppData\Roaming\Winamp\demo.mp3
C:\Users\Administrator\AppData\Roaming\Winamp\demo.m
C:\Users\Administrator\AppData\Roaming\Winamp\demo.p
C:\Users\Administrator\AppData\Roaming\Winamp\demo.3
C:\Users\Administrator\AppData\Roaming\Winamp\gen_jumpex.m3u8
C:\Users\Administrator\AppData\Roaming\Winamp\links.xml
C:\Users\Administrator\AppData\Roaming\Winamp\links.x
C:\Users\Administrator\AppData\Roaming\Winamp\links.m
C:\Users\Administrator\AppData\Roaming\Winamp\links.l
C:\Users\Administrator\AppData\Roaming\Winamp\Plugins
C:\Users\Administrator\AppData\Roaming\Winamp\studio.xnf
C:\Users\Administrator\AppData\Roaming\Winamp\winamp.ini
C:\Users\Administrator\AppData\Roaming\Winamp\Winamp.m3u
C:\Users\Administrator\AppData\Roaming\Winamp\winamp.m3u8
C:\Users\Administrator\AppData\Roaming\Winamp\Winamp.q1
C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\gen_ml.ini
C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\gen_mud.ini
C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\milk2_img.ini
C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\milk2_msg.ini
C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\ml
C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\omBrowser

评分

参与人数 1金钱 +15 收起 理由
afan + 15 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2012-3-31 11:33:11 | 显示全部楼层
试试这个
.*\.mp3|.*\.xml
 楼主| 发表于 2012-3-31 11:41:54 | 显示全部楼层
回复 2# xms77


怎样对结果取反啊?  就是只替换不以 .mp3 或 .xml 结尾的行
发表于 2012-3-31 12:09:57 | 显示全部楼层
不反也行啊,提取以 .mp3 或 .xml 结尾的行,返写入原文件(写入模式2)
 楼主| 发表于 2012-3-31 12:15:40 | 显示全部楼层
回复 4# shqf


    我不是要写入文件啊,提取后后面还要继续用的
发表于 2012-3-31 12:20:02 | 显示全部楼层
回复 5# Qokelate


#include <Array.au3>

Local $sStr = "C:\Users\Administrator\AppData\Roaming\Trine2\options.txt" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\TTPlayer\cache" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\VMware\inventory.vmls" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\VMware\preferences.ini" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\auth.ini" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\demo.mp3" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\demo.m" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\demo.p" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\demo.3" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\gen& _jumpex.m3u8" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\links.xml" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\links.x" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\links.m" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\links.l" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\Plugins" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\studio.xnf" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\winamp.ini" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\Winamp.m3u" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\winamp.m3u8" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\Winamp.q1" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\gen& _ml.ini" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\gen& _mud.ini" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\milk2& _img.ini" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\milk2& _msg.ini" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\ml" & @CRLF _
                        & "C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\omBrowser"

MsgBox(0, 1, $sStr)

Local $aStr = StringRegExp($sStr, ".*\.mp3|.*\.xml", 3)

If IsArray($aStr) Then
        $sStr = _ArrayToString($aStr, @CRLF)
        MsgBox(0, 2, $sStr)
EndIf

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2012-3-31 12:36:28 | 显示全部楼层
回复 6# happytc


    明白!  3Q
发表于 2012-3-31 13:43:57 | 显示全部楼层
Local $Str = _
                'C:\Users\Administrator\AppData\Roaming\Trine2\options.txt' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\TTPlayer\cache' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\VMware\inventory.vmls' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\VMware\preferences.ini' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\auth.ini' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\demo.mp3' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\demo.m' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\demo.p' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\demo.3' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\gen_jumpex.m3u8' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\links.xml' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\links.x' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\links.m' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\links.l' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\Plugins' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\studio.xnf' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\winamp.ini' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\Winamp.m3u' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\winamp.m3u8' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\Winamp.q1' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\gen_ml.ini' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\gen_mud.ini' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\milk2_img.ini' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\milk2_msg.ini' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\ml' & @CRLF & _
                'C:\Users\Administrator\AppData\Roaming\Winamp\Plugins\omBrowser'
MsgBox(0, '原字符串', $Str)
Local $Test = StringRegExpReplace($str, '(?mi)^.+?(?:(?!\.mp3|\.xml).){4}(?:\r\n|\z)', '')
MsgBox(0, '替换结果', $Test)

评分

参与人数 1金钱 +20 收起 理由
Qokelate + 20 正则强人!

查看全部评分

发表于 2012-7-28 09:40:34 | 显示全部楼层
学习一下~~~~~
发表于 2016-9-30 00:11:45 | 显示全部楼层
学习下哦 谢谢了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-17 01:29 , Processed in 0.091334 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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