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

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:

About johnpupu

..........
This entry was posted in 有的沒的 and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
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