Qokelate 发表于 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

xms77 发表于 2012-3-31 11:33:11

试试这个
.*\.mp3|.*\.xml

Qokelate 发表于 2012-3-31 11:41:54

回复 2# xms77


怎样对结果取反啊?就是只替换不以 .mp3 或 .xml 结尾的行

shqf 发表于 2012-3-31 12:09:57

不反也行啊,提取以 .mp3 或 .xml 结尾的行,返写入原文件(写入模式2)

Qokelate 发表于 2012-3-31 12:15:40

回复 4# shqf


    我不是要写入文件啊,提取后后面还要继续用的

happytc 发表于 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

Qokelate 发表于 2012-3-31 12:36:28

回复 6# happytc


    明白!3Q

afan 发表于 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)

seafish 发表于 2012-7-28 09:40:34

学习一下~~~~~

酷儿 发表于 2016-9-30 00:11:45

学习下哦 谢谢了
页: [1]
查看完整版本: 已解决 正则表达式如何按词匹配?