in reply to RegEx Question

Simple approach:

D:\>perl -lne "print /^[0-8]{9}$/ && !/(.)(?=.*\1)/ ? 'ok' : 'not ok'" 1234 not ok 1234567689 not ok 012345678 ok 018273645 ok 010101010 not ok ^Z

And with one regexp:

D:\>perl -lne "print /^(?:([0-8])(?!.*\1)){9}$/ ? 'ok' : 'not ok'" 123456780 ok 123123123 not ok 123456781 not ok ^Z

Replies are listed 'Best First'.
Re^2: RegEx Question
by Marshall (Canon) on Sep 10, 2009 at 08:01 UTC
    Simple approach:
    D:\>perl -lne "print /^[0-8]{9}$/ && !/(.)(?=.*\1)/ ? 'ok' : 'not ok'"

    This is short and very clever, but "simple"? I think NOT.
    Also, I didn't see in the OP spec that this was an exact sequence of 9 digits.

      Well, its simplier than the second approach :>
      And sequence of 9 or 8 digits is mentioned in discussion above