Ruby on rails 轨道。Regex帮助确定文档类型是否为文档
我正在尝试创建一个正则表达式,当内容类型为:application/msword或text/rtf时,该正则表达式将返回true) 我有以下资料:Ruby on rails 轨道。Regex帮助确定文档类型是否为文档,ruby-on-rails,regex,ruby-on-rails-3,Ruby On Rails,Regex,Ruby On Rails 3,我正在尝试创建一个正则表达式,当内容类型为:application/msword或text/rtf时,该正则表达式将返回true) 我有以下资料: def istext? if !(attachment.content_type =~ %r{^(application|(x-)?application)/(msword|rtf)$}) return false else return true end end 关于如何让这个方法在appl
def istext?
if !(attachment.content_type =~ %r{^(application|(x-)?application)/(msword|rtf)$})
return false
else
return true
end
end
关于如何让这个方法在application/msword或text/rtf中返回true,在其他任何情况下返回false,有什么聪明的想法吗
谢谢为什么要使用正则表达式
def istext?
%w(application/msword text/rtf).include?(attachment.content_type)
end