Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Linux 正規表示式通配符 . (句點) 詳解:任意單一字元匹配與轉義實例

編輯:Linux 系統常見問題解答

在正規表示式中,句點 . 代表**除換行符外的任意單一字元** (awk 中甚至可匹配內嵌換行)。

範例:匹配 Intel 晶片型號

80.86

可匹配 80286、80386、80486 等。若需匹配字面句點,需轉義 \.。

位置限制

chapter. 僅匹配 chapter 後接任一字元的字串。若 chapter 位於行尾,chapter. 不匹配,但 chapter 仍匹配。

$ grep 'Chapter.' sample
you will find several examples in Chapter 9.
"Quote me ' Chapter and Verse' ," she said.
Chapter Ten

上例三行皆匹配;若改用 Chapter 無句點,結果相同。差異在於行尾情境。

延伸: 正規表示式引擎差異 (BRE/ERE/PCRE) 影響 . 行為,編寫複雜模式時請確認工具支援語法 (grep -E、sed -r、perl、python re 等)。

Copyright © Windows教程網 All Rights Reserved