正規式 (a|b) 和 正規式 [ab] 兩者皆可匹配1個a或1個b,所以匹配效果一樣。 但是兩者的語法不同,表達能力也不同,說明如下: []表示匹配中括號(bracket)內字元集合的一個字元,所以只能匹配1個字元; ()表示匹配小括號(parenthesis)內直槓(vertical bar,|)隔開的任一正規式,所以可能匹配不止1個字元。 例如: 1.正規式 hello 匹配 hello 5個字元 2.正規式 [hello] 匹配 h或e或l或o 任1個字元 3.正規式 (hello) 匹配 hello 5個字元 4.正規式 (hello|world) 匹配 hello 或 world 5個字元 5.正規式 ([hello]|world) 匹配 h或e或l或o 任1個字元 或 world 5個字元 參考: difference b/w [ab] and (a|b) in regex match?
regular expressions (a|b) and [ab] are the same?
訂閱:
文章 (Atom)
Disable UDP to solve frequent RDP disconnection
解決 RDP 遠端桌面經常斷線問題:「關閉 UDP 傳輸」 在使用 Windows 內建的 遠端桌面(RDP, Remote Desktop Protocol) 連線時,你是否也常遇到連線突然卡死、畫面凍結,或是頻繁跳出「連線已中...