找回密码
 加入
搜索
楼主: 流沙枫

[效率算法] 文本有条件替换...... [已解决]

 火.. [复制链接]
发表于 2012-3-20 14:57:42 | 显示全部楼层
当然,别忘了写入文件(如果需要的话)
Local $sFile = @ScriptDir & '\需要替换的文件.txt'
Local $Str = FileRead($sFile)
Local $sReplace = StringRegExpReplace($str, '(?i)disabled=no(.+\s+.+name=\h*(\H.+?)\h*password=\h*\2)', 'disabled=yes$1')
If Not @Error And @Extended = 0 Then Exit MsgBox(48, '注意', '没啥可换 ')
Local $Extended = @Extended
FileDelete($sFile)
If FileWrite($sFile, $sReplace) Then MsgBox(64, '完成', '成功替换 ' & $Extended & ' 处 ')
 楼主| 发表于 2012-3-20 15:26:56 | 显示全部楼层
回复 16# afan

可以了,大神太牛了,非常感谢...
回去一定好好研究下代码意思!
只怪自己当初学艺不精,让大大劳神了!!
发表于 2012-3-20 15:44:51 | 显示全部楼层
afan的正则简直用的是出神入化了,看得我头晕呵,我等还需要大大地努力啊。
 楼主| 发表于 2012-3-20 21:08:01 | 显示全部楼层
回复 16# afan


    $str, '(?i)disabled=no(.+\s+.+name=\h*(\H.+?)\h*password=\h*\2)', 'disabled=yes$1'


大大,能再帮解释下这行正则式意思么?
看了会,还是不太理解......
发表于 2012-3-20 21:11:57 | 显示全部楼层
回复  afan


    $str, '(?i)disabled=no(.+\s+.+name=\h*(\H.+?)\h*password=\h*\2)', 'disabled=yes ...
流沙枫 发表于 2012-3-20 21:08



    不好解释,解释出来就成你在一楼表述的要求了。
主要在于 (\H.+?) 以及 \2 ,这两个就是判断是否存在一样了。
 楼主| 发表于 2012-3-20 21:20:23 | 显示全部楼层
回复 20# afan


    .
Match any character except newline
\s
Match any whitespace character
*
Repeat any number of times
+
Repeat one or more times

正则式里的符号意思?
发表于 2012-3-20 21:23:37 | 显示全部楼层
回复 21# 流沙枫


    有中文帮助文档,看看 StringRegExp 函数解释
 楼主| 发表于 2012-3-20 21:30:59 | 显示全部楼层
回复 22# afan

好的,谢谢啦,努力补习中....
(?i) Case-insensitivity flag. This does not operate as a group. It tells the regular expression engine to do case-insensitive matching from that point on.

\h any horizontal whitespace character.

\H any character that is not a horizontal whitespace character.

* Repeat the previous character, set or group 0 or more times. Equivalent to {0,}

2 Return array of matches including the full match (Perl / PHP style).
发表于 2012-3-20 21:53:55 | 显示全部楼层
当然,别忘了写入文件(如果需要的话)
afan 发表于 2012-3-20 14:57


这里留个记号,看看 '没啥可换 ' 这句我能用否?

    http://www.autoitx.com/forum.php ... 091&fromuid=161
 楼主| 发表于 2012-3-20 22:05:38 | 显示全部楼层
回复 22# afan


    $1是计算加1么?
发表于 2012-3-20 22:06:32 | 显示全部楼层
引用第1个组
 楼主| 发表于 2012-3-20 22:18:43 | 显示全部楼层
回复 26# afan


    name=\h*
password=\h*

\h*是重输出name= 和password=?
发表于 2012-3-20 22:20:10 | 显示全部楼层
\h* 是指匹配 0到尽量多个 空格
发表于 2012-3-20 22:40:23 | 显示全部楼层
楼主用的是ROS软路由,学习了
 楼主| 发表于 2012-3-20 22:41:59 | 显示全部楼层
回复 28# afan


.+? 匹配字符串是否再出现?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-19 14:04 , Processed in 0.074319 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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