views:

122

answers:

1

I have a small plugin for Rails where I add permalinks to my model without storing them (the permalink) in the database (http://github.com/nhocki/make_permalink).

I forked the plugin from a friend and changed the regex, but I don't really know how to make a more friendly and readable regex.

I want to remove all the á, é, í (characters with 'tilde') with the actual vowel without the 'comma' above (á turns into a; é into e...)

I know that /[Á-Úá-ú]/=~"é' works but I don't really know how to change them to the actual [A-Ua-u].

My friend told me that maybe we could do something like: gsub(/([Á-Úá-ú])/, my_method($1))

but I don't really know what to do in that method. Is there a way to substract some value that every 'á' turns into 'a' and 'é' into 'e' and so on? To make all the changes into one or two Regex?

Thanks, Nicolás Hock Isaza

+1  A: 

Iconv ought to do you nicely:

http://ruby-doc.org/stdlib/libdoc/iconv/rdoc/index.html

And some examples:

Lukas
Thanks, that works perfectly!
Hock
glad it worked! saved me a time or two :)
Lukas