https://gerardnico.com/ide/notepad/replace
https://notepad-plus-plus.org/community/topic/16787/find-and-replace-using-regular-expressionphp
http://www.pnotepad.org/docs/search/regular_expressions/git
TotalErrSaAddr=(.,) //5955 (包含0 和1~9) TotalErrSaAddr=(..,) //63 TotalErrSaAddr=(...,) //2 TotalErrSaAddr=(....,) //0 TotalErrSaAddr=(*,) //error TotalErrSaAddr=(.,) //5955 ============== TotalErrSaAddr=([0],) //4714 TotalErrSaAddr=([1-9],) //1241 TotalErrSaAddr=([1-8],) //1230 TotalErrSaAddr=([9],) //11 TotalErrSaAddr=([1-9][0-9],) // 63 TotalErrSaAddr=([1-9][0-9][0-9],) //2 ^case "TotalErrSaAddr=/(\w+)\.php" ^case 「TotalErrSaAddr=/[a-Z0-9]*" TotalErrSaAddr=>0 ([^-]*).* ([^TotalErrSaAddr=]*).* TotalErrSaAddr=([^-]*).* //ok 3010 TotalErrSaAddr=([a-Z0-9]*) TotalErrSaAddr=([1-9],) //ok 1241 TotalErrSaAddr=([9-999],) //ok, 11個, 9~999個錯誤saAddrNum TotalErrSaAddr=([0-9],) //ok 5955 ,0~9的數據,後面跟, TotalErrSaAddr=([^-]*) //ok 6020 TotalErrSaAddr= //ok 6020 TotalErrSaAddr= BINON:00000000,00000000,00000000,0000([1-3])([1-3])([1-3])([1-3]); //找 ??3的值, ?能夠是空到任意 BINON:00000000,00000000,00000000,0000(.[3])
https://blog.csdn.net/wangkai_123456/article/details/55254598正則表達式
在咱們處理文件時,不少時候會用到查找與替換。當咱們想將文件中某一部分替換替換文件中另外一部分時,怎麼辦呢? 下面正則表達式 給我提供方法。express
正則表達式,提供複雜 而且彈性的查找與替換安全
注意: 不支持多行表達式 (involving \n, \r, etc).ide
要選上
正則表達式搜索ui
1 基本表達式
符號 | 解釋 |
---|---|
. | 匹配任意字符,除了新一行(\n)。也就是說 「.」能夠匹配 \r ,當文件中同時含有\r and \n時,會引發混亂。要匹配全部的字符,使用\s\S |
(…) | 這個匹配一個標籤區域. 這個標籤能夠被訪問,經過語法 \1訪問第一個標籤, \2 訪問第二個, 同理 \3 \4 … \9。 這些標籤能夠用在當前正則表達式中,或則替search和replace中的換字符串。 |
\1, \2, etc | 在替換中表明1到9的標籤區域(\1 to \9)。例如, 查找字符串 Fred([1-9])XXX 並替換爲字符串 Sam\1YYY的方法,當在文件中找到Fred2XXX的字符串時,會替換爲Sam2YYY。注意: 只有9個區域能使用,因此咱們在使用時很安全,像\10\2 表示區域1和文本」0」以及區域2。 |
[…] | 表示一個字符集合, 例如 [abc]表示任意字符 a, b or c.咱們也可使用範圍例如[a-z] 表示因此的小寫字母。 |
[^…] | 表示字符補集. 例如, [^A-Za-z] 表示任意字符除了字母表。 |
^ | 匹配一行的開始(除非在集合中, 以下). |
$ | 匹配行尾. |
* | 匹配0或屢次, 例如 Sa*m 匹配 Sm, Sam, Saam, Saaam 等等. |
+ | 匹配1次或屢次,例如 Sa+m 匹配 Sam, Saam, Saaam 等等. |
? | 匹配0或者1次, 例如 Sa?m 匹配 Sm, Sam. |
{n} | 匹配肯定的 n 次.例如, ‘Sa{2}m’ 匹配 Saam. |
{m,n} | 匹配至少m次,至多n次(若是n缺失,則任意次數).例如, ‘Sa{2,3}m’ 匹配 Saam or Saaam. ‘Sa{2,}m’ 與 ‘Saa+m’相同 |
*?, +?, ??, {n,m}? | 非貪心匹配,匹配第一個有效的匹配,一般 ‘<.>’ 會匹配整個 ‘content’字符串 –但 ‘<.?>’ 只匹配 」 .這個標記一個標籤區域,這些區域能夠用語法\1 \2 等訪問多個對應1-9區域。 |
2 標記和分組
符號 | 解釋 |
---|---|
(…) | 一組捕獲. 能夠經過\1 訪問第一個組, \2 訪問第二個. |
(?:…) | 非捕獲組. |
(?=…) | 非捕獲組 – 向前斷言. 例如’(.*)(?=ton)’ 表達式,當 遇到’Appleton’字符串時,會匹配爲’Apple’. |
(?<=…) | 非捕獲組 – 向後斷言. 例如’(?<=sir) (.*)’ 表示式,當遇到’sir William’ 字符串時,匹配爲’ William’. |
(?!…) | 非捕獲組 – 消極的向前斷言. 例如’.(?!e)’ 表達式,當遇到’Apple’時,會找到每一個字母除了 ‘l’,由於它緊跟着 ‘e’. |
(? | 非捕獲組 – 消極向後斷言. 例如 ‘(? |
(?P…) | 命名所捕獲的組. 提交一個名稱到組中供後續使用,例如’(?PA[^\s]+)\s(?P=first)’ 會找到 ‘Apple Apple’. 相似的 ‘(A[^\s]+)\s\1’ 使用組名而不是數字. |
(?=name) | 匹配名爲name的組. (?P…). |
(?#comment) | 批註 –括號中的內容在匹配時將被忽略。 |
3 特殊符號
符號 | 解釋 |
---|---|
\s | 匹配空格. 注意,會匹配標記的末尾. 使用 [[:blank:]] 來避免匹配新一行。 |
\S | 匹配非空白 |
\w | 匹配單詞字符 |
\W | 匹配非單詞字符 |
\d | 匹配數字字符 |
\D | 匹配非數字字符 |
\b | 匹配單詞邊界. ‘\bW\w+’ 找到W開頭的單詞 |
\B | 匹配非單詞邊界. ‘\Be\B+’ – 找到位於單子中間的字母’e’ |
< | This matches the start of a word using Scintilla’s definitions of words. |
> | This matches the end of a word using Scintilla’s definition of words. |
\x | 運行用x來表達可能具備其餘意思的字符。例如, [ 用來插入到文本中做爲[ 而不是做爲字符集的開始. |
4 字符類
符號 | 解釋 |
---|---|
[[:alpha:]] | 匹配字母字符: [A-Za-z] |
[[:digit:]] | 匹配數字字符: [0-9] |
[[:xdigit:]] | 匹配16進制字符: [0-9A-Fa-f] |
[[:alnum:]] | 匹配字母數字字符: [0-9A-Za-z] |
[[:lower:]] | 匹配小寫字符: [a-z] |
[[:upper:]] | 匹配大寫字符: [A-Z] |
[[:blank:]] | 匹配空白 (空格 or tab):[ \t] |
[[:space:]] | 匹配空白字符:[ \t\r\n\v\f] |
[[:punct:]] | 匹配標點字符: [-!」#$%&’()*+,./:;<=>?@[]_`{ |
[[:graph:]] | 匹配圖形字符: [\x21-\x7E] |
[[:print:]] | 匹配可打印的字符 (graphical characters and spaces) |
[[:cntrl:]] | 匹配控制字符 |
5 替換操做
使用正則表達式的標記,經過()來包圍想要用的字符,而後用\1 來替換字符串,第一個匹配文本。spa
例如: Text body Search string Replace string Result Hi my name is Fred my name is (.+) my name is not \1 Hi my name is not Fred The quick brown fox jumped over the fat lazy dog brown (.+) jumped over the (.+) brown \2 jumped over the \1 The quick brown fat jumped over the fox lazy dog
6 限制
Support for regular expressions in PN2 is currently limited, the supported patterns and syntax are a very small subset of the powerful expressions supported by perl. 最大的限制是正則表達式只能匹配單行,不能用多行匹配表達。能夠用Backslash Expressions代替. 準備計劃是使用PCRE庫 library (used elsewhere in PN2) 來支持文檔搜索.
7應用舉例
方法: 選擇替換,把查找模式設置爲正則表達式,在查找框中輸入 ^\s+ ,替換框留空,點「所有替換」,便可(先全選)。 刪除全部行s字符開始後面的全部字符 方法: 選擇替換,把查找模式設置爲正則表達式,在查找框中輸入 ^([^:]*):.*$,替換框填寫$1,點「所有替換」,便可(先全選)。