regular expressions (a|b) and [ab] are the same?

正規式 (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?

沒有留言:

how to deal with metric scale inconsistency in topn recommendation evaluation

🎯 推薦系統一般會回傳前 N 個排名的物品清單給用戶,稱為 Top‑N 推薦。 遇到推薦模型須要訓練及評估時,習慣先蒐集用戶與物品的互動資料,再將資料拆分成沒有重疊的訓練集及測試集。 模型在訓練時只看得到訓練集,評估時則拿測試集作為驗證的標準答案,以免作...

總網頁瀏覽量