From: Luiz Angelo Daros de Luca Date: 2011-08-11T08:24:35+09:00 Subject: Re: regex position error --000e0cd29a26981cd704aa2efb90 Content-Type: text/plain; charset=UTF-8 Dear Camargo, /((^| )[ -']|[^\D'- ]/ or something like this 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 > > 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. > --000e0cd29a26981cd704aa2efb90--