I just tried to teach myself how to use regular expressions so sorry if this seems trivial to some.
I am doing a little crib script. He uses the standard deck of playing cards, and I use CDHS (clubs, diamonds, hearts, spades) for suits and A2..9TJQK (ace, 2 ... 9, 10, jack, queen, king) for takes.
I have a $hand variable, which is a line with even lines. For example, S2HA3D is 2 S2HA3D , an ace of hearts and 3 diamonds, respectively. Please note that the suit and rank can be in any order.
I use:
preg_match_all("/[2-9ATJQK][CDHS]|[CDHS][2-9ATJQK]/i", $hand, $result);
to find all the cards, but this returns the suits and ranks in the order found.
My question is, how can I get the result to give a ranking first for each card, regardless of the given order. I hope I have clearly stated this.
source share