EditPlus的查找,替換,文件中查找支持以下的正則表達(dá)式:
Expression Description
t Tab character.
n New line.
. Matches any character.
| Either expression on its left and right side matches the target string.
For example, “a|b” matches “a” and “b”.
[] Any of the enclosed characters may match the target character.
For example, “[ab]” matches “a” and “b”. “[0-9]” matches any digit.
[^] None of the enclosed characters may match the target character.
For example, “[^ab]” matches all character EXCEPT “a” and “b”.
“[^0-9]” matches any non-digit character.
* Character to the left of asterisk in the expression should match 0 or more times.
For example “be*” matches “b”, “be” and “bee”.
+ Character to the left of plus sign in the expression should match 1 or more times.
For example “be+” matches “be” and “bee” but not “b”.
? Character to the left of question mark in the expression should match 0 or 1 time.
For example “be?” matches “b” and “be” but not “bee”.
^ Expression to the right of ^ matches only when it is at the beginning of line.
For example “^A” matches an “A” that is only at the beginning of line.
$ Expression to the left of $ matches only when it is at the end of line.
For example “e$” matches an “e” that is only at the end of line.
() Affects evaluation order of expression and also used for tagged expression.
scape character. If you want to use character “” itself, you should use “\”.
例子:
原始串
str[1]abc[991];
str[2]abc[992];
str[11]abc[993];
str[22]abc[994];
str[111]abc[995];
str[222]abc[996];
str[1111]abc[997];
str[2222]abc[999];
目標(biāo)串:
abc[1];
abc[2];
abc[11];
abc[22];
abc[111];
abc[222];
abc[1111];
abc[2222];
處理:
查找串:str[([0-9]+)]abc[[0-9]+]
替換串:abc[1]
【1】正則表達(dá)式應(yīng)用――替換指定內(nèi)容到行尾
原始文本如下面兩行
abc aaaaa
123 abc 444
希望每次遇到“abc”,則替換“abc”以及其后到行尾的內(nèi)容為“abc efg”
即上面的文本最終替換為:
abc efg
123 abc efg
解決:
① 在替換對(duì)話框,查找內(nèi)容里輸入“abc.*”
② 同時(shí)勾選“正則表達(dá)式”復(fù)選框,然后點(diǎn)擊“全部替換”按鈕
其中,符號(hào)的含義如下:
“.” =匹配任意字符
“*” =匹配0次或更多
注意:其實(shí)就是正則表達(dá)式替換,這里只是把一些曾經(jīng)提出的問題加以整理,單純從正則表達(dá)式本身來(lái)說(shuō),就可以引申出成千上萬(wàn)種特例。
【2】正則表達(dá)式應(yīng)用――數(shù)字替換
希望把
asdadas123asdasdas456asdasdasd789asdasd
替換為:
asdadas[123]asdasdas[456]asdasdasd[789]asdasd
在替換對(duì)話框里面,勾選“正則表達(dá)式”復(fù)選框;
在查找內(nèi)容里面輸入“[0-9][0-9][0-9]”,不含引號(hào)
“替換為:”里面輸入“[