The regular expression matches in any order

I am trying to use the program to find out which hand you are playing poker. The template object that I create is in a format for checking five cards, each of which is determined by a value, and then a suit. So, for example, an ace of spades will be designated as As. I have the following code for recognizing a straight line, but it only works in order. How can I recognize a line 5d4sAc3s2has straight? Thanks for any help!

Pattern[] floppedStraightCheck;
floppedStraightCheck = new Pattern[10];
floppedStraightCheck[0] = Pattern.compile("(([aA][scdhSCDH])([2][scdhSCDH])([3][scdhSCDH])([4][scdhSCDH])([5][scdhSCDH])");
+4
source share
2 answers

, . , a regular expression . , . , , - not .

+2

. and, .

^(?=.*[aA][scdhSCDH])(?=.*2[scdhSCDH])(?=.*3[scdhSCDH])(?=.*4[scdhSCDH])(?=.*5[scdhSCDH]).{10}$

Regular expression visualization

Debuggex

:

^(?=(..)*[aA])(?=(..)*2)(?=(..)*3)(?=(..)*4)(?=(..)*5)(.[scdhSCDH]){5}$

Regular expression visualization

Debuggex

+1

Source: https://habr.com/ru/post/1537140/


All Articles