2013-01-03 91 views
3

我知道捕获组(?:模式)开头的问号表示此模式不应创建反向引用,但在以下示例中,问号在通配符后面的捕获组的末尾??在捕获组的末尾

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 
+0

另请参阅http://stackoverflow.com/q/13401514/10396 – AShelly

回答