down by the river - regex and poker cards
June 29, 2009 1:40 PM
Subscribe
looking for regex expert to help with replacing playing card references
Hello mefite regex experts!
I am trying to process a string to find and replace playing card references. When texas hold ‘em poker players express playing cards they use a number of formats, for example ‘7-7’ to indicate a pair of sevens or ‘7-8-9’ to show the three card flop. They also show cards with their suits, for example ‘kc-kd-kh’ to show king clubs, king diamonds and king hearts. However, the ‘-‘ are arbitrary, they could use spaces ‘kc kd kh’, commas etc. AND they are variable length, so I need to find ‘A-A’ ‘7-8-9-10-j’ and ‘7c-8c-9c-10c’.
I want to find these strings and replace them with HTML (using ColdFusion) and I am looking to the regexp which will allow me to process things like:
‘xCx’ or ‘xCxCx’ or ‘xCxCxCx’ or ‘xCxCxCxCx’ or ‘xCxCxCxCxCx’ where ‘x’ is any one of a number of special characters (space, comma, !, period, -, etc.) and ‘C’ is one of 2,3,4,5,6,7,8,9,10,j,q,k,a. (casing to be ignored)
I also need to find and replace ‘xCSx’, ‘xCSxCSx’, etc, where ‘S’ is the suit – c, h, d or s.
One further complication is that when I replace the suit (‘S’) string, I need to replace it with the HTML symbol - ♠ etc. and wrap a class around it so ‘ KC ’ would become ‘ [span class=’card’] K [span class=’blacksuit’]♣[/span] [/span] ’.
(I am using [ ] instead of angle brackets to preserver the formatting!).
Is this possible? Is it too much for a single regexp??? Thanks for all help!
posted by the_very_hungry_caterpillar to computers & internet (10 comments total)
1 user marked this as a favorite
posted by Dr Dracator at 1:49 PM on June 29