I have
file_ext = attach.document_file_name.capture(/\.[^.]*$/)
but i guess there is no method capture.
I'm trying to get the file extension from a string. I don't yet have the file.
I have
file_ext = attach.document_file_name.capture(/\.[^.]*$/)
but i guess there is no method capture.
I'm trying to get the file extension from a string. I don't yet have the file.
You can do RegEx match in ruby like so:
file_ext = (/\.[^.]*$/.match(attach.document_file_name.to_s)).to_s
Fore more information please check http://ruby-doc.org/core/classes/Regexp.html
There is also the built-in ruby function File.extname:
file_ext = File.extname attach.document_file_name
(with the difference that File.extname('hello.')
returns ''
, whereas your regex would return '.'
)