Thanks for your help. I found a solution that works fine:
/( |-|')( |-|')|^( |-|')|( |-|')$|^$|\d|[^a-z
çáäãàâéèëêíìïöóòôõüúùû\-\']/i
The solution proposed by De Luca doesn't work for some characters (e.g.
"?").
Try to follow the KISS principle. As a rule of thumb,
when something is getting too much complex, you might be doing it wrong.
Regards,
···
---
Luiz Angelo Daros de Luca, Me.
luizluca@gmail.com
2011/8/10 Ryan Davis <ryand-ruby@zenspider.com>
On Aug 10, 2011, at 15:19 , Carlos Camargo wrote:
> I have a regular expression:
> Regexp.new(/^(\w+([-']\w+)*)(\ \w+([-']\w+)*)+$/)
Regexp.new(regexp) is the same as regexp. Don't wrap in Regexp.new for no
reason.
> and I need to know the position of a invalid character.
>
> For example, if a invalid character is a number, I can recover it using:
> "gisele bund9chen".index(/\d/)
/\d/ is to /[0-9]/ as /\D/ is to /[^0-9]/
> But, I need generalize the regular expression to find any a character
> different of \w, space \' and \-.
For more goodies see the regexp section of the ruby quickref.