匹配多行正则的使用 - 文本软件 /Multiline/RegExp/ By Stabx

标题: 匹配多行正则的使用 - 文本软件 /Multiline/RegExp/ By Stabx

正文:

QUOTE:

匹配多行正则的使用 - 文本软件 /Multiline/RegExp/ By Stabx

软件为 UltraEdit && EditPlus && Search and Replace 

1. 抬头见天, 鄙人觉得匹配多行好用顺序为: EditPlus, Search and Replace, UltraEdit 
2. 功能为: Search and Replace, EditPlus, UltraEdit
3. 复杂性为: UltraEdit, Search and Replace, EditPlus
4. 小体会: UE 的 Macro 是小孩子玩的碰碰车, SR 的 Script 是登月用的火箭
注: 以上内容, 排名有分先后

目录: 
1. UltraEdit
2. EditPlus
3. Search and Replace
附: 一个 UE 的 宏 和一个 SR 的脚本

shawl.qiu<shawl.qiuATgmail.com>
绿色学院 | http://blog.csdn.net/btbtd/
2006-6-13


CODE:

CODE:

CODE:

CODE:

附: 一个 UE 的 宏 和一个 SR 的脚本

2. SR 的脚本
目的: 替换 维基百科 页面中我不需要的内容, 并为各个链接重新加上适当链接.
替换后: 只剩下 标题和内容
注: 该脚本适用于维基百科所有语言所有内容页

CODE:

1. UE 的宠
目的: 替换 HTML 大写标签 为小写

CODE:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Loop 
Find MatchCase RegExp "<[A-Z][A-Z0-9]+"
IfFound
ToLower
Else
ExitLoop
EndIf
EndLoop
Top
Loop 
Find MatchCase RegExp "[ ^t^p][A-Z]+[=>]"
IfFound
ToLower
EndSelect
Key LEFT ARROW
Else
ExitLoop
EndIf
EndLoop
Top
UnixReOn

[Script for Search and Replace]
[Options]
Search_subdir=0
Prompt_flag=0
Max Display Chars=4096
Show Progress Dialog=1
Count across files=0
Replace Processing=0
Process Binary Files=1
Output_File=
Show_Files=1
Backup Path=G:/My Documents/replace_backup/
Before Hit=<
After Hit=>
Max Reg Expr=32767
Write to Backup Dir=0
Unzip Dir=D:/DOCUME~1/Phoenix.GI/LOCALS~1/Temp/
Show Files Without Hits=0
Display Replace String=1
Display File Stats=1
Show File Date and Size=1
Reverse Filters=0
Min Size Filter=0
Max Size Filter=0
Min Date Filter=
Max Date Filter=
Skip Files Mask=0
Ignore Attributes=55
Keep file time stamp=0
One hit=0
Sort File Names=0
Sort Ascending=1
Append to output file=0
[Search /ix]
<!DOCTYPE*[]dtd">/n
[Replace]

[Search /ix]
<html*[]">/n
[Replace]

[Search /ix]
<head>*[]/n*[]</head>/n
[Replace]

[Search /ix]
<body*[]>*[]/n*[]<h1 class="firstHeading">
[Replace]
<h1 class="firstHeading">
[Search /ix]
<div class="visualClear"></div>*[]/n*[]
[Replace]
<div class="visualClear"></div></div>
[Search /i]
images/at_pic/
[Replace]

[Search /ix]
http/:*("/wiki/Category:|"/wiki/)*title/=/"*?/"
[Replace]
"tag.asp?id=tag&tag=%3%4"
[Search /ix]
"http/:*?/w/*?/=*?*/&/;*?edit/"
[Replace]
"tag.asp?id=tag&tag=%6%7"
[Search /ix]
<script type="text/javascript">*[]</script>
[Replace]

[Search /ix]
/<div*?/[*?/]/<//div/>
[Replace]

[Search /ix]
("/wiki/Category:|"/wiki/)*title/=/"
[Replace]
"tag.asp?id=tag&tag=
[Search /ix]
"/w/*?/=*?*/&/;*?edit/"
[Replace]
"tag.asp?id=tag&tag=%4%5"
[Search /ix]
Category/:
[Replace]

[Search /ix]
/"/w/*article=*/"
[Replace]
"tag.asp?id=tag&tag=%2"
[Search /ix]
src/=/"*/.(png|gif|jpg|jpeg|bmp)*?/"
[Replace]
src="images/at_pic/%1.%2%3"
[Search /ix]
src/=/"http/:upload*?longdesc/=/"*?/:*?/"
[Replace]
src="images/at_pic/%5%6"
[Search /ix]
src/=/"//skins-1.5//common//images//*/.(png|gif|jpg|jpeg|bmp)"
[Replace]
src="images/at_pic/%1.%2"
[End of Search and Replace Script]

1. UltraEdit
使用心得: 这个软件所谓的 /p or ^p 基本上就是一个摆设, 稍为复杂一点的内容就会耍小家子脾气.
注: UltraEdit 正则分 UltraEdit Syntax || Unix Syntax, 以下使用 Unix Syntax

正则:
--------------
查找: {.*/p*}
替换: (空)
--------------
查找以下内容, 目的删除 { 和 } 中的内容, 包括 {}
    body {
        font: 14px Arial, Helvetica, sans-serif;
        width: 762px;
        padding: 0px;
        margin:0px auto;
        background: transparent url(images/gi_50_410.png) left top fixed no-repeat;
    }
结果:     body 
    //注意! 有时鼠标须移至匹配对象的前面, 有时撒消上次操作就会给你一个 1G 以上的临时文件, 且外加半翘机.
    //如果拷贝以上格式, 需加上跳格符, 如: {.*/p*/t}

2. EditPlus
EP 替换多行的正则很够简单, 可目前已不使用 EP, 改用 UE.
目的: 删除掉 head 标签和该标签中的内容
正则: 
--------------
查找: <head>.*/n.*</head>
替换: (空)
--------------
例:

CODE:
结果为: (空)

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>绿色学院 Green Institute</title>
<style type="text/css">/*<![CDATA[*/ @import "css/css_first/ctindex.css"; /*]]>*/</style>
<script type="text/javascript" src="js/js.js"></script>
</head>

3. Search and Replace
sr 的替换正则其实一点也不复杂, 复杂和不懂的迷糊的是, 使用正则和 选项设置或脚本设置 严重有关系, 不过也很严重的够强劲.

正则: 
--------------
查找: <head>*[]/n*[]</head>
替换: (空)
--------------
目的: 删除掉 head 标签和其内容
例: 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>绿色学院 Green Institute</title>
<style type="text/css">/*<![CDATA[*/ @import "css/css_first/ctindex.css"; /*]]>*/</style>
<script type="text/javascript" src="js/js.js"></script>
</head>
结果: (空)

//注: 如果查找的内容够长, 需要到 视图 中的 选项 里的 搜索设置足够大的默认搜索字数, 否则对的正则也会变成错的.
//另外: 如果使用脚本, 则需要在 视图 中的 脚本 中的 高级中的 选项里 的搜索 设置足够大的字数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值