Posted on 2007-07-06 19:39
dennis 閱讀(411)
評論(0) 編輯 收藏 所屬分類:
動態語言
用了這么久ruby,知道String對象可以通過[]操作得到字符或者子字符串,比如:
>"abc"[0]
97
>"abc"[0,2]
"ab"
97就是字符a的ASCII碼了,卻不知道[]操作同樣可以接受正則表達式,返回匹配正則的那部分字符串,比如:
>"has 5 and 3" [/\d+/]
5
>"hello there"[/(..)e/]
the
ruby的API設計充分體現了馬教主所說的
人本接口。