Robert Klemme wrote:
>>> irb(main):009:0> /^(.)(?!\1)(.)(?!\1|\2)(.)(\2)$/ =~ "abcb"
>>> => 0
>>> irb(main):010:0> /^(.)(?!\1)(.)(?!\1|\2)(.)(\2)$/ =~ "abbb"
>>> => nil
> 
> The problem with this approach is that it does not work for strings of
> arbitrary length.  Even if you adjust it to work for multiple lengths
> you always have a fixed upper limit for which it can work.

The OP explicitly said that he wanted to match single characters. It 
would also make sense for other fixed-width fields, or delimited fields.

With neither fixed sizes nor delimiters, I don't think it makes any 
sense. It would become "match any sequence of characters, followed by 
any sequence of characters which isn't the same as the first sequence of 
characters, followed by any sequence of characters which isn't the first 
or second, followed by the second sequence of characters". And there 
would be a squillion different ways to try and slice the string to make 
it match.
-- 
Posted via http://www.ruby-forum.com/.