Regex to check that a character in range doesn't repeat

Posted by Aly on Stack Overflow See other posts from Stack Overflow or by Aly
Published on 2010-03-21T13:51:35Z Indexed on 2010/03/21 14:01 UTC
Read the original article Hit count: 400

Hi, I want to match against Strings such as AhKs & AdKs (i.e. two cards Ah = Ace of Hearts). I want to match two off-suit cards with a regex, what I currently have is "^[AKQJT2-9][hscd]{2}$", but this could match hands such as AhKh (suited) and AhAh. Is there a way to possibly use backreferences to say the second [hscd] cannot be the same as the firs (similarly for [AKQJT2-9])

© Stack Overflow or respective owner

Related posts about regex

Related posts about regular-expression