VIM — Matching a line break 跨行比對 & Non-Greedy

December 1, 2007

Matching a line bread Doc
Non-Greedy Reference

<input name=”inst6″ type=”radio” value=”4″>
<a href=”javascript:;” onMouseOver=”MM_swapImage(‘q2′,”,’images/qa_p_HTC%20TyTN.jpg’,1)” onMouseOut=”MM_swapImgRestore()”><img src=”images/0-HTC%20TyTN.gif” name=”htc” width=”100″ height=”15″ border=”0″ id=”htc”></a>

因為想讓input radio 也有onMouseOver 的效果
所以想把<a href=”javascript:;” onMouseOver=”MM_swapImage(‘q2′,”,’images/qa_p_HTC%20TyTN.jpg’,1)” onMouseOut=”MM_swapImgRestore()”>也加在<input name=”inst6″ type=”radio” value=”4″>這個tag 的前面…然後後面再加</a>
因為很多行我不想一行一行傻傻的改所以…..就用regexp 了…

這邊包含了兩個技巧一個是non-greedy,一個是 Matching a line break
\(<input name=”inst[0-9]*.*>\)\(\_s\+\)\(<a href=”javascript:;.\{-}>\)/\3\1<\/a>\3/gc

這樣就可以全部換掉了…Orz
我沒仔細檢查過,剛剛看replace 完後是很work…..
::-p:

tags: ,
posted in 有的沒的 by johnpupu

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org