On Fri, May 29, 2009 at 5:48 PM, Brian Candler <b.candler / pobox.com> wrote: > Harry Kakueki wrote: >> Somehow I have the syntax wrong. > > Yes - I don't think a backreference like \1, which could contain any > number of characters, is usable inside a character class [...], which is > a list of individual characters. > > irb(main):005:0> /[^\1]/ =~ "a" > => 0 > irb(main):006:0> /[^\1]/ =~ "1" > => 0 > irb(main):007:0> /[^\1]/ =~ "\001" > => nil > > So it seems that [^\1\2] means any character apart from \001 (ctrl-A) or > \002 (ctrl-B) > > I think you need a negative lookahead assertion. > * http://www.ruby-doc.org/docs/ProgrammingRuby/ > * click on "The Ruby Language" > * scroll to "Extensions" > * look for (?!re) > > irb(main):009:0> /^(.)(?!\1)(.)(?!\1|\2)(.)(\2)$/ =~ "abcb" > => 0 > irb(main):010:0> /^(.)(?!\1)(.)(?!\1|\2)(.)(\2)$/ =~ "abbb" > => nil > -- > Posted via http://www.ruby-forum.com/. > > Brian, I need to read that section carefully to be sure I understand. But, I think that does the trick. Thank you! Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/ruby/list.html