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])
I want to match against Strings such as AhKs & AdKs (i.e. two cards
Share
Try this regular expression:
Here a negative look-ahead assertion
(?!…)is used to disallow the fourth character to be the same as the second (match of first grouping).But if the regular expression implementation does not support look-around assertions, you will probably need to expand it to this: