放飞我心 2008-1-13
UltraEdit是被大家广泛使用的编辑器,其功能强大已为众人所见识,不过可能你还没有尝试过在其中使用正则表达式,或者想使用而遇到了挫折,今天我就简单说说如何在UltraEdit中使用正则表达式。
UltraEdit中的正则表达式与Unix风格的标准正则表达式有些区别:
UltraEdit语法风格的正则表达式规则如下:
Symbol(符号)
|
Function(功能)
|
%
|
Matches the start of line - Indicates the search string must be at the beginning of a line but does not include any line terminator characters in the resulting string selected.
匹配行首。
|
$
|
Matches the end of line - Indicates the search string must be at the end of line but does not include any line terminator characters in the resulting string selected.
匹配行尾。
|
?
|
Matches any single character except newline.
匹配除新行以外的任意单字符。
|
*
|
Matches any number of occurrences of any character except newline.
匹配除新行以外的任意数量的字符(没有或多个)。
|
+
|
Matches one or more of the preceding character/expression. At least one occurrence of the character must be found. Does not match repeated newlines.
匹配一次或多次前导字符或表达式。
|
++
|
Matches the preceding character/expression zero or more times. Does not match repeated newlines.
匹配任意次前导字符或表达式。
|
^b
|
Matches a page break.
匹配分页符。
|
^p
|
Matches a newline (CR/LF) (paragraph) (DOS Files)
匹配DOS风格的换行符(/x0D/x0A)。
|
^r
|
Matches a newline (CR Only) (paragraph) (MAC Files)
匹配MAC风格的换行符(/x0D)。
|
^n
|
Matches a newline (LF Only) (paragraph) (UNIX Files)
匹配UNIX风格的换行符(/x0A)。
|
^t
|
Matches a tab character.
匹配TAB字符。
|
[ ]
|
Matches any single character or range in the brackets.
匹配中括号范围内的任意单字符。
|
^{A^}^{B^}
|
Matches expression A OR B.
匹配表达式A或者表达式B。
|
^
|
Overrides the following regular expression character.
重载紧接着的正则表达式字符,类似于转义字符。
|
^(正则表达式^)
|
Brackets or tags an expression to use in the replace command. A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression.
The corresponding replacement expression is ^x, for x in the range 1-9. Example: If ^(h*o^) ^(f*s^) matches "hello folks", ^2 ^1 would replace it with "folks hello". 标记一个表达式用于替换命令。
|
下面我们以一些实际例子来说明正则表达式在UltraEdit中的应用吧:
1. 查找包含不区别分大小写的“ir”的单词并将其替换成“IR”。
查找:[iI][rR]
替换:IR
比如有如下文本:
bird bIrd cird ciRd
替换后的结果为:
bIRd bIRd cIRd cIRd
2.将下面形式的语句:
10:54:32.3> Sys Time=0x46150532, GetTitle 22 425 69 26 0 242 22 13[换行]
[空行]
…
替换成:
GetTitle 22 425 69 26 0 242 22 13[换行]
的方法是:
查找:%*^(GetTitle*^)^p^p
替换:^1^p
总之,只要搞清了正则表达式的一般用法,对付这种特殊的正则表达式只需要看下它的语法(如上面的表格)就可以了。