我知道捕獲組(?:模式)開頭的問號表示此模式不應創建反向引用,但在以下示例中,問號在通配符後面的捕獲組的末尾??在捕獲組的末尾
self =~ /(.*?)_(\d+)$/
代碼
class String
# used to instantiate a model based on a dom_id style
# identifier like "person_10"
def to_model
self =~ /(.*?)_(\d+)$/
class_name, id = $1, $2
class_name.classify.constantize.find(id)
end
end
另請參閱http://stackoverflow.com/q/13401514/10396 – AShelly