Robert Klemme wrote:
> 2009/5/29 Brian Candler <b.candler / pobox.com>:
>> The OP explicitly said that he wanted to match single characters. It
>> would also make sense for other fixed-width fields, or delimited fields.
> 
> But he did not state explicitly that the _strings_ that he wanted to
> analyze have fixed length.  This is where your approach breaks.

But he's not just looking for strings with non-repeating characters. 
Note the rule that says the fourth character must be equal to the second 
character. This is an application-specific rule; I don't think we can 
logically extend that to guess what the rule for the fifth or subsequent 
characters would be.

>> 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.
> 
> That's beyond the power of regular expressions.

It's perfectly possible to express it as a regular expression, but you 
have to beware that there could be many ways for it to match, so you 
might not get what you expect.

>> /^(.+)(?!\1)(.+)(?!\1|\2)(.+)(\2)$/.match("foowibbleboingwibble").to_a
=> ["foowibbleboingwibble", "foowibbl", "e", "boingwibbl", "e"]
>> /^(.+?)(?!\1)(.+?)(?!\1|\2)(.+?)(\2)$/.match("foowibbleboingwibble").to_a
=> ["foowibbleboingwibble", "foo", "wibble", "boing", "wibble"]
-- 
Posted via http://www.ruby-forum.com/.