一輩子受用的 Regular Expressions
兼談另類的電腦學習態度

講者: 洪朝貴 http://people.ofset.org/~ckhung/ ==> 演講簡報
單位:

什麼是 Regular Expressions?

這份講稿已過時; 建議改參考 新的講義

範例一: 搜尋字串

用某個指令 ... /port/ ... 找出所有的 "port" 字串

4.3.12. Jaz and ZIP Drives

     * Jaz-Drive-HOWTO, Jaz-drive HOWTO
       Updated: Jan 2000. Covers the configuration and use of the 1Gb and
       2Gb Iomega Jaz drives under Linux.
     * ZIP-Install, Installing Linux on ZIP disk using ppa ZIP Drive
       Mini-Howto
       Updated: Jan 1998. This document is only useful for those with the
       printer port version of a ZIP drive who wish to have either a
       portable or backup Linux system on a ZIP disk.
     _________________________________________________________________

4.3.14. Modems

     * Linmodem-HOWTO, Linmodem-Mini-HOWTO
       Updated: Feb 2001. Describes Linmodem (winmodem hardware) support
       under Linux.
     * Modem-HOWTO, Modem HOWTO
       Updated: Jun 2005. Help with selecting, connecting, configuring,
       trouble-shooting, and understanding modems for a PC.

範例二: 代換字串

用某個指令 ... s/(\d+)\/(\d+)/$2\/$1/ ... 把每列的第一對 "以斜線分開的數字" 對調過來:

The test is scheduled on 1/25.
The actual video conference
will be held on 1/26.
==>
The test is scheduled on 25/1.
The actual video conference
will be held on 26/1.

例三: 批次更改檔名

public_html/ 目錄底下有三四層目錄, 數百個 *.shtml 檔, 欲全部改名為 *.php。

find public_html/ -name '*.shtml' | perl -pe 's/(.*)\.shtml/ mv $1.shtml $1.php/' | bash

public_html/index.en.shtml
public_html/p/toy/index.shtml
public_html/p/index.shtml
public_html/s/pr/index.shtml
public_html/s/edu.shtml
public_html/s/os.shtml
public_html/dl/index.shtml
public_html/fe/index.shtml
public_html/fe/footer.shtml
public_html/a/c000.shtml
public_html/a/c041.shtml

==>
 mv public_html/index.en.shtml public_html/index.en.php
mv public_html/p/toy/index.shtml public_html/p/toy/index.php
mv public_html/p/index.shtml public_html/p/index.php
mv public_html/s/pr/index.shtml public_html/s/pr/index.php
mv public_html/s/edu.shtml public_html/s/edu.php
mv public_html/s/os.shtml public_html/s/os.php
mv public_html/dl/index.shtml public_html/dl/index.php
mv public_html/fe/index.shtml public_html/fe/index.php
mv public_html/fe/footer.shtml public_html/fe/footer.php
mv public_html/a/c000.shtml public_html/a/c000.php
mv public_html/a/c041.shtml public_html/a/c041.php

基本概念

[三種 regexp 句型]

細節

細節詳見 講義; 也參考 「如何有效學習電腦」 當中 "分析流量", "合併成績", "批次改檔名" 等幾個實用範例。

結論: 眼光放遠, 不要盲從, 做最有價值的學習投資

[絕地企鵝]