I've only just been trying to teach myself how to use regular expressions so sorry if this seems trivial to some.
I'm making a little crib script. It uses a standard deck of playing cards and I'm using CDHS (clubs, diamonds, hearts, spades) for suits and A2..9TJQK (ace, 2...9, 10, jack, queen, king) for the ranks.
I have variable $hand which is an even-length string of cards. For example, S2HA3D would be the 2 of spades, ace of hearts and 3 of diamonds respectively. Note the suit and rank can be either way round.
I'm using:
preg_match_all("/[2-9ATJQK][CDHS]|[CDHS][2-9ATJQK]/i", $hand, $result);
to find all the cards but this returns suits and ranks in the order found.
My question is how can I make the result give the rank first for each card, regardless of the order given. I hope I've worded this clearly.