在notepad++時,以regular expression於行頭/行尾加入字符

在Windows上的Notepad++、或者Mac上的Textwrangler時,過去,當我要在
整個檔案內容的行頭或行尾加入特定的字符時,通常都只會用簡單去取代\r\l\n之類的斷行符號。

然而,這方法在最首和最尾的一行時,就要改回人手,而視乎文字檔的斷行格式是CR、LF還是CRLF,尋找.取代時,要用\n\r還是\l也很麻煩。

Regular expression (regex)就是大救星!

Regular Expression很神很好用… 但絕不容易。有些時候,像行頭行尾,就超簡單:

行首的話,尋找的字元是:^
行尾首的話,尋找的字元是:$

然後取代成你要的文字即成。

BTW,不同OS間的文字檔的End of line關係大概是:

  • windows<cr><lf>
  • Macintosh<cr>
  • Unix<lf>

Top Ten List on Using a Computer in an Office

10. If you got problems, you should try turn the machine off and turn it on again.

09. USB is a port (or an input-output interface) on a modern computer, not a storage device.

08. Microsoft Powerpoint is for On-screen presentation, NOT note printing, please use Word for that.

07. Microsoft Word is for simple document to print out on a laser or inkjet printer, NOT for publishing a 300 pages book.

06. You can email a line of text in an email, you don’t NEED to type a sentence in a Word Document, save it and attach it in an Email.

05. You can also email with a PICTURE as attachment, you can add them just like attaching your favorite Word or Excel Documents. You don’t NEED to put a JPEG photo in a Word Document, save it and attach it in an Email.

04. People can actually read your email faster than you press the print button, go pick up your print out , then walk to their desk with a piece of paper with a line of text on it. If they don’t have any respond from your email, they’re probably ignoring you.

03. You can save a HTML file from Word or Microsoft Frontpage and uploaded it somewhere. But doesn’t mean you know how to do Web-design or “writing a web page”.

02. Don’t click on YES everytime anything pop up with a dialog box, READ first, OUT LOUD if necessary.

01. The blue “e” thingy on your desktop with “Internet Explorer” text under it is NOT the Internet, more like it fucks up the internet!