UltraEdit正则表达式使用(Regular Expressions in UltraEdit)
正则表达式作为模式匹配,经常用于查找/替换操作的特定字符串。使用正则表达式来简化操作和提高效率的方式有许多。下面列出了一个用于ultra - edit样式和unix样式正则表达式的参考以及一些示例,演示如何在ultra - edit中使用正则表达式
Regular Expressions in UltraEdit |
||
UltraEdit Symbol |
UNIX Symbol |
Function |
% |
^ |
Matches/anchors the beginning of line. 行首 |
$ |
$ |
Matches/anchors the end of line. 行尾 |
? |
. |
Matches any single character except a newline character. Does not match repeated newlines. 单个字符 |
* |
Matches any number of occurrences of any character except newline. 0-n个字符 |
|
+ |
+ |
Matches one or more of the preceding character/expression. At least one occurrence of the character must be found. Does not match repeated newlines. 1-n个字符 |
++ |
* |
Matches the preceding character/expression zero or more times. Does not match repeated newlines. |
^ |
\ |
Indicates the next character has a special meaning. "n" on its own matches the character "n". "^n" (UE expressions) or "\n" (UNIX expressions) matches a linefeed or newline character. 转义符. |
[ ] |
[ ] |
Matches any single character or range in the brackets. 括弧内匹配一个或某个范围的单字符 |
[~xyz] |
[^xyz] |
A negative character set. Matches any characters NOT between brackets.括弧内匹配除这个或这个范围的单字符 |
^b |
\f |
Matches a page break/form feed character.分页符 |
^p |
\p |
Matches a newline (CR/LF) (paragraph) (DOS Files). DOS换行符 |
^r |
\r |
Matches a newline (CR Only) (paragraph) (MAC Files).MAC换行符 |
^n |
\n |
Matches a newline (LF Only) (paragraph) (UNIX Files).UNIX换行符 |
^t |
\t |
Matches a tab character.制表符 |
[0-9] |
\d |
Matches a digit character.一个数字 |
[~0-9] |
\D |
Matches a non-digit character.除了数字的符号 |
[ ^t^b] |
\s |
Matches any white space including space, tab, form feed, etc., but not newline. 空格 |
[~ ^t^b] |
\S |
Matches any non-white space character but not newline. 非空格(除换行) |
\v |
Matches a vertical tab character.垂直制表符 |
|
[0-9a-z_] |
\w |
Matches any alphanumeric character including underscore. 一个标识符 |
[~0-9a-z_] |
\W |
Matches any character except alphanumeric characters and underscore. 非标识符 |
^{A^}^{B^} |
(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. 子组 |
^1 |
\1 |
Numerical reference to tagged expressions. Text matched with tagged expressions may be used in Replace commands with this format. 反向引用子组的匹配值 |
Note: ^ refers to the character '^' NOT Control Key + value. ^是一个字符,不是Ctrl键 |
使用样例(UltraEdit/UNIX Regular Expression Examples)
简单字符串匹配(Simple String Matching)
简单的字符串匹配是正则表达式最基本的形式,不但快速而且可以方便地一次搜索多个字符串,无须执行多个查找操作。
UltraEdit RegExp:
Find What: m?n
Matches: "man" and "men" but not "moon"
Find What: t*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").
Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"
UNIX RegExp:
Find What: m.n
Matches: "man" and "men" but not "moon"
Find What: t.*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").
Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"
Character Sets
A character set is a group of characters bounded by "[" and "]". These may be used to designate specific characters to be matched or ranges (i.e. [aeud], or [a-z]).
UltraEdit RegExp:
Find What: [aeiou]
Matches: every vowel
NOTE: Regular Expressions in UltraEdit are not case-sensitive unless Match Case is selected in the Find dialog.
Find What: [,.^?]
Matches: a literal ",", "." or "?".
Because the "?" is a symbol used in expressions it must be "escaped" for the literal character to be matched rather than interpreted as an expression.
Find What: [0-9a-z]
Matches: any digit or letter
Find What: [~0-9]
Matches: any character except a digit (~ means NOT the following)
UNIX RegExp:
Find What: [aeiou]
Matches: every vowel
Find What: [,\.?]
Matches: a literal ",", "." or "?".
Because the "." is a symbol used in expressions it must be "escaped" for the literal character to be matched rather than interpreted as an expression.
Find What: [0-9a-z]
Matches: any digit or letter
Find What: [^0-9]
Matches: any character except a digit (^ means NOT the following)
OR Expressions
Currently UltraEdit only allows for the specification of two operands for an OR expression. You may search for an expression A or B as follows:
UltraEdit RegExp:
Find What: ^{John^}^{Tom^}
UNIX RegExp:
Find What: (John|Tom)
There should be nothing between the two expressions. You may combine A or B and C or D in the same search as follows:
UltraEdit RegExp:
Find What: ^{John^}^{Tom^} ^{Smith^}^{Jones^}
UNIX RegExp:
Find What: (John|Tom) (Smith|Jone)
This will search for "John" or "Tom" followed by "Smith" or "Jones".
Deleting Blank Lines
With Regular Expressions selected in the Replace dialog this will match the a CR/LF (DOS line terminator) immediately followed by the end of a line (i.e., a blank line) and replace it with nothing, effectively deleting it:
UltraEdit RegExp:
Find What: ^p$
Replace With: (literally nothing)
UNIX RegExp:
Find What: \p$
Replace With: (literally nothing)
Reformatting Text With Tagged Expressions
Example 1:
Tagged expressions may be used to mark various data members so that they may be reorganized, reformatting the data. For example, it might be useful to be able to rearrange:
John Smith, 385 Central Ave., Cincinnati, OH, 45238
into:
45238, Smith, John, 385 Central Ave., Cincinnati, OH
UltraEdit RegExp:
Find What: %^([a-z]+^) ^([a-z]+^), ^(*^), ^(*^), ^(*^), ^([0-9]+^)
Replace With: ^6, ^2, ^1, ^3, ^4, ^5
UNIX RegExp:
Find What: ^([a-z]+) ([a-z]+), (.*), (.*), (.*), ([0-9]+)
Replace With: \6, \2, \1, \3, \4, \5
Example 2:
If you have a web-based registration system it might be useful to rearrange the order data into a format easily used by a database:
name = John Smith
address1 = 385 Central Ave.
address2 =
city = Cincinnati
state = OH
zip = 45238
into:
John Smith, 385 Central Ave.,, Cincinnati, OH, 45238,
This can be done with the following expression:
UltraEdit RegExp:
Find What: name = ^([a-z ]+^)^paddress1 = ^([a-z 0-9.,]+^)^paddress2 = ^([a-z 0-9.,]++^)^pcity = ^([a-z]+^)^pstate = ^([a-z]+^)^pzip = ^([0-9^-]+^)
Replace With:^1, ^2, ^3, ^4, ^5, ^6
UNIX RegExp:
Find What: name = ([a-z ]+)\paddress1 = ([a-z 0-9.,]+)\paddress2 = ([a-z 0-9.,]*)\pcity = ([a-z]+)\pstate = ([a-z]+)\pzip = ([0-9^-]+)
Replace With:\1, \2, \3, \4, \5, \6
UltraEdit正则表达式使用(Regular Expressions in UltraEdit)相关推荐
- 正则表达式(Regular Expressions)
正则表达式(Regular Expressions) 正则表达式在其他编程语言中的应用非常广泛,网上资料也非常多,而网上在ABAP语言中应用的资料却很少,尽管各语言中正则表达式语法知识都很类似,但仍然 ...
- Codewars-Javascript训练手册:正则表达式(Regular Expressions)
Autocomplete! Yay!(字符串自动补全) The autocomplete function will take in an input string and a dictionary ...
- python中正则表达式中_python 中 正则表达式(Regular Expressions)学习
刚接触了python中的re模块,由于之前没有对正则表达式进行系统性的学习,学起来很费劲,因此写下这篇博客进行积累和巩固,以备后用. 正则表达式的应用是非常广泛的,不论是在linux中还是在编程中,我 ...
- 【转】ultraedit 正则表达式
UltraEdit风格正则表达式语法 1.% 功能说明: 匹配一行的开始位置.这个符号表示所寻找的字符在每一行的开始的位置,不包括每一行其上一行的结束字符. 2.$ 功能说明:匹配一行的结束位置.这个 ...
- UltraEdit正则表达式文本替换
UltraEdit风格正则表达式语法 1.% 功能说明: 匹配一行的开始位置.这个符号表示所寻找的字符在每一行的开始的位置,不包括每一行其上一行的结束字符. 2.$ 功能说明:匹配一行的结束位置.这个 ...
- .NET Regular Expressions
HTML去空白回车换行 private static readonly Regex REGEX_LINE_BREAKS = new Regex(@"\n\s*", RegexOpt ...
- 《D o C P》学习笔记(3 - 0)Regular Expressions, other languages and interpreters - 简介
Regular Expressions, other languages and interpreters 你可以学到什么: 定义正则表达式的语言:解释这个语言. 定义被1个正则表达式匹配的字符串集合 ...
- 《D o C P》学习笔记(3 - 1)Regular Expressions, other languages and interpreters - Lesson 3
备注1:每个视频的英文字幕,都翻译成中文,太消耗时间了,为了加快学习进度,我将暂停这个工作,仅对英文字幕做少量注释. 备注2:将.flv视频文件与Subtitles文件夹中的.srt字幕文件放到同1个 ...
- 斯坦福大学Dan Jurafsky主讲NLP笔记 2.1 Regular Expressions
2.1 regular expressions 正则表达式 2.1.1 问题的提出 在英语中,有大小写和单复数的问题,例如: woodchuck woodchucks Woodch ...
最新文章
- 《OpenCV3编程入门》学习笔记6 图像处理(四)形态学滤波(2):开运算、闭运算、形态学梯度、顶帽、黑帽
- C++ STL容器——序列式容器(array、vector、deque、list)
- 金蝶K3,如何添加其它出库单出库类型
- 斯坦福CS224n追剧计划【大结局】:NLP和深度学习的未来
- sql 存储过程返回值 变量名
- 鸟哥的私房菜Linux 学习笔记之 Bash语法
- Python当前线程休眠1秒钟
- 【Vue US国际会议】使用Vue和NativeScript来开发吸引人的原生手机app
- MySQL 中的数据类型介绍
- (转)关于最近疯狂流行的文件夹变成exe文件的病毒查杀办法
- Java躲子弹课设,Robocode高手的诀窍 - 躲避子弹[Java编程]
- 双稳态继电器工作原理图_常见的继电器及工作原理
- Codevs P1066 引水入城 2010年NOIP全国联赛提高组
- ohci之usb_submit_urb
- C/C++常用函数总结以及在ubuntu和vs中运行
- [SHOI2008] 小约翰的游戏
- 【 linux 从入门到放弃(全网最详细虚拟机及c7安装)】
- UVA:1593 代码对齐
- android.view.ContextThemeWrapper cannot be cast to android.app.Activity
- 台式计算机idc数据排名,2019年电脑销量排行_IDC:2019年中国PC市场预测销量持续走低...