??
??
???因?yàn)樾枰褂肗otepad++ 來(lái)過(guò)濾一些字符如下:

???首先按照字面的特征,寫(xiě)正則表達(dá)式如下:
??\[.*\]\(https:.+\),測(cè)試匹配

??
??
??
???查閱Notepad++的在線幫助,找到正則表達(dá)式的相關(guān)內(nèi)容:
Multiplying operators
+? This matches 1 or more instances of the previous character, as many as it can. For example,Sa+mmatchesSam,Saam,Saaam, and so on.[aeiou]+matches consecutive strings of vowels.*? This matches 0 or more instances of the previous character, as many as it can. For example,Sa*mmatchesSm,Sam,Saam, and so on.?? Zero or one of the last character. ThusSa?mmatchesSmandSam, but notSaam.*?? Zero or more of the previous group, but minimally: the shortest matching string, rather than the longest string as with the “greedy” operator. Thus,m.*?oapplied to the textmargin-bottom: 0;will matchmargin-bo, whereasm.*owill matchmargin-botto.+?? One or more of the previous group, but minimally.{?}? Matches ? copies of the element it applies to (where ? is any decimal number).{?,}? Matches ? or more copies of the element it applies to.{?,?}? Matches ? to ? copies of the element it applies to, as much it can (where ? ≥ ?).{?,}?or{?,?}?? Like the above, but mimimally.*+or?+or++or{?,}+or{?,?}+? These so called “possessive” variants of greedy repeat marks do not backtrack. This allows failures to be reported much earlier, which can boost performance significantly. But they will eliminate matches that would require backtracking to be found. As an example:
??When regex “.*”is run against the text“abc”x:
“ matches “
.* matches abc”x
” cannot match $ ( End of line ) => Backtracking
“ matches “
.* matches abc”
” cannot match letter x => Backtracking
“ matches “
.* matches abc
” matches ” => 1 overall match “abc”
??When regex “.*+”, with a possessive quantifier, is run against the text “abc”x :
“ matches “
.*+ matches abc”x ( catches all remaining characters )
” cannot match $ ( End of line )
??Notice there is no match at all for the possive version, because the possessive repeat factor prevents from backtracking to a possible solution
??
??
??
???注意關(guān)鍵說(shuō)明如下:
-
*?? Zero or more of the previous group, but minimally: the shortest matching string, rather than the longest string as with the “greedy” operator. Thus,m.*?oapplied to the textmargin-bottom: 0;will matchmargin-bo, whereasm.*owill matchmargin-botto.
??加入*?表示前一個(gè)字符出現(xiàn)0次或者無(wú)限多次,但是是最小匹配。結(jié)合剛才的需求分析:

???運(yùn)行結(jié)果如下:

??為什么呢?仔細(xì)分析正則表達(dá)式,原來(lái)問(wèn)題出現(xiàn)在了前面:

??前面的這個(gè)\[.*\]沒(méi)有進(jìn)行限定,依然是最大匹配,現(xiàn)在在這里也加上?,看測(cè)試結(jié)果:
