Regular expression are really useful. Unfortunately, they are not always the best way of doing things.
Particularly when transformations you want to make are easy.
I wanted to know how to get file extension from filename the fastest way possible. There is 3 natural way of doing this:
<div><codeclass="ruby">
# regexp
str.match(/[^.]*$/);
ext=$&
# split
ext=str.split('.')[-1]
# File module
ext=File.extname(str)
</code></div>
At first sight I believed that the regexp should be faster than the split because it could be many `.` in a filename. But in reality, most of time there is only one dot and I realized the split will be faster. But not the fastest way. There is a function dedicated to this work in the `File` module.