I am trying to capture the board after every hand of a poker game. Each hand has a summary section in which the board is summarized as follows:
string = "*** SUMMARY ***Total pot Rupees 971.44 | Rake Rupees 46.24Board [2s Qh 8s 7c]Seat 1: lesterr276 folded before Flop (didn't bet)Seat 2: davinder125 folded on the TurnSeat 3: ProfessorOfCard (button) collected (Rupees 925.20)Seat 4: warmachine1997 (small blind) folded before FlopSeat 6: harsha164 (big blind) folded on the Turn"
As you can see the Board was [2s Qh 8s 7c] in the above hand. Now a lot of hands end before the flop, in which case there is no board. Hence, the board may or may not be a part of the summary.
I want the regex to capture the board if it is present in the Summary or return a None object if it is not present. I have used the following code to capture the board and it works fine:
re.search(r'\*{1,} SUMMARY \*{1,}.*?(Board (.*?\]))', string).group(1)
But when I add a "?" to make the board group optional, it does not work as expected and returns an empty object:
re.search(r'\*{1,} SUMMARY \*{1,}.*?(Board (.*?\]))?', string).group(1)
What am I doing wrong?