From: Ryan Davis Date: 2011-08-11T07:33:31+09:00 Subject: Re: regex position error 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.