找回密码
 加入
搜索
查看: 1431|回复: 2

[AU3基础] [已解决]求一个正则表达式

[复制链接]
发表于 2016-5-6 17:01:07 | 显示全部楼层 |阅读模式
本帖最后由 hnfeng 于 2016-5-9 11:36 编辑

文件中有很多 <ProductKey>........</ProductKey> 这样的文本段,想根据里面的 key 来删掉相应的文本段,但是我使用的表达式会把 第一个 <ProductKey> 到满足条件的 </ProductKey> 之间多个段全删掉。
下面的代码,想要的结果是删掉含有 $a_KeyS 的 文本段(第二段),保留第一段。先谢谢了

local $t_CilxFile="xxxxx   " & @CRLF & _
"   <ProductKey>" & @CRLF & _
"        <KeyDescription>Office15_AccessVL_MAK-Alpha</KeyDescription>" & @CRLF & _
"        <KeyId>12345-02162-202-843362-00-2052-7601.0000-0752015</KeyId>" & @CRLF & _
"        <KeyType>Mak</KeyType>" & @CRLF & _
"        <KeyValue>N3H26-DPD66-4QFF7-DYB3D-KKVT3</KeyValue>" & @CRLF & _
"        <LastUpdate xsi:nil=""true"" />" & @CRLF & _
"        <LastErrorCode>0</LastErrorCode>" & @CRLF & _
"        <RemainingActivations>-1</RemainingActivations>" & @CRLF & _
"        <SupportedEditions>ProPlusRetail</SupportedEditions>" & @CRLF & _
"        <SupportedSku>064383fa-1538-491c-859b-0ecab169a0ab</SupportedSku>" & @CRLF & _
"        <UserRemarks />" & @CRLF & _
"        <KeyTypeName>MAK</KeyTypeName>" & @CRLF & _
"      </ProductKey>" & @CRLF & _
"      <ProductKey>" & @CRLF & _
"        <KeyDescription>Office16_AccessVL_MAK</KeyDescription>" & @CRLF & _
"        <KeyId>12345-02162-201-810144-00-2052-7601.0000-0752015</KeyId>" & @CRLF & _
"        <KeyType>Mak</KeyType>" & @CRLF & _
"        <KeyValue>N4CPB-2W4QY-HTRPD-GC6GM-KD43D</KeyValue>" & @CRLF & _
"        <LastUpdate xsi:nil=""true"" />" & @CRLF & _
"        <LastErrorCode>0</LastErrorCode>" & @CRLF & _
"        <RemainingActivations>-1</RemainingActivations>" & @CRLF & _
"        <SupportedEditions>ProPlusRetail</SupportedEditions>" & @CRLF & _
"        <SupportedSku>064383fa-1538-491c-859b-0ecab169a0ab</SupportedSku>" & @CRLF & _
"        <UserRemarks />" & @CRLF & _
"        <KeyTypeName>MAK</KeyTypeName>" & @CRLF & _
"      </ProductKey>    xxxxxxxxxx"

MsgBox(0,0,$t_CilxFile)
Local $a_KeyS="N4CPB-2W4QY-HTRPD-GC6GM-KD43D"
$t_CilxFile=StringRegExpReplace($t_CilxFile, "(?s)<ProductKey>.*?" & $a_KeyS & ".*?</ProductKey>","")
MsgBox(0,0,$t_CilxFile)
发表于 2016-5-6 21:06:19 | 显示全部楼层
楼主是这个意思么?这句正则也是之前别人帮我写的,我照着拆开看能看懂,不照着看自己写又写不出来,脑瓜不好使了。

local $t_CilxFile="xxxxx   " & @CRLF & _
"   <ProductKey>" & @CRLF & _
"        <KeyDescription>Office15_AccessVL_MAK-Alpha</KeyDescription>" & @CRLF & _
"        <KeyId>12345-02162-202-843362-00-2052-7601.0000-0752015</KeyId>" & @CRLF & _
"        <KeyType>Mak</KeyType>" & @CRLF & _
"        <KeyValue>N3H26-DPD66-4QFF7-DYB3D-KKVT3</KeyValue>" & @CRLF & _
"        <LastUpdate xsi:nil=""true"" />" & @CRLF & _
"        <LastErrorCode>0</LastErrorCode>" & @CRLF & _
"        <RemainingActivations>-1</RemainingActivations>" & @CRLF & _
"        <SupportedEditions>ProPlusRetail</SupportedEditions>" & @CRLF & _
"        <SupportedSku>064383fa-1538-491c-859b-0ecab169a0ab</SupportedSku>" & @CRLF & _
"        <UserRemarks />" & @CRLF & _
"        <KeyTypeName>MAK</KeyTypeName>" & @CRLF & _
"      </ProductKey>" & @CRLF & _
"      <ProductKey>" & @CRLF & _
"        <KeyDescription>Office16_AccessVL_MAK</KeyDescription>" & @CRLF & _
"        <KeyId>12345-02162-201-810144-00-2052-7601.0000-0752015</KeyId>" & @CRLF & _
"        <KeyType>Mak</KeyType>" & @CRLF & _
"        <KeyValue>N4CPB-2W4QY-HTRPD-GC6GM-KD43D</KeyValue>" & @CRLF & _
"        <LastUpdate xsi:nil=""true"" />" & @CRLF & _
"        <LastErrorCode>0</LastErrorCode>" & @CRLF & _
"        <RemainingActivations>-1</RemainingActivations>" & @CRLF & _
"        <SupportedEditions>ProPlusRetail</SupportedEditions>" & @CRLF & _
"        <SupportedSku>064383fa-1538-491c-859b-0ecab169a0ab</SupportedSku>" & @CRLF & _
"        <UserRemarks />" & @CRLF & _
"        <KeyTypeName>MAK</KeyTypeName>" & @CRLF & _
"      </ProductKey>    xxxxxxxxxx"
 
MsgBox(0,0,$t_CilxFile)
Local $a_KeyS="N4CPB-2W4QY-HTRPD-GC6GM-KD43D"
$t_CilxFile=StringRegExpReplace($t_CilxFile, "(?s)<ProductKey>(?:(?!ProductKey>).)*?" & $a_KeyS & ".*?</ProductKey>","")
MsgBox(0,0,$t_CilxFile)
 楼主| 发表于 2016-5-6 21:49:17 | 显示全部楼层
回复 2# zch11230


    非常感谢!
经初步测试没问题,就是这个意思。
没看懂,为何是 (?!ProductKey>) ,我换为 (?!<ProductKey>) 或 (?!</ProductKey>) 好像也可以。

(?s)<ProductKey>(?:(?!ProductKey>).)*?" & $a_KeyS & ".*?</ProductKey>
(?s)<ProductKey>(?:(?!<ProductKey>).)*?" & $a_KeyS & ".*?</ProductKey>
(?s)<ProductKey>(?:(?!</ProductKey>).)*?" & $a_KeyS & ".*?</ProductKey>
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-22 20:45 , Processed in 0.085298 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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