我正在尝试解析我的扑克牌手牌历史,以确定我在花色下打了7胜2负的牌的数量(也就是说,7是属于一套的,2是属于另一套的)。
我可以拿到我玩过77或22的牌
$ grep -E "Dealt to .* \[([7|2])[s|c|h|d]\s\1" ~/poker/handhistory/*/* | wc -l
15以及我在同一套花色中玩过72次的手。
$ grep -E "Dealt to .* \[([7|2])([s|c|h|d])\s[7|2]\2" ~/poker/handhistory/GMulligan/* | wc -l
9我已经捕获了第一张牌的等级。我想做的是有一个字符类,如果第一个捕获组是2,则包含7,如果第一个捕获组是7,则包含2。
这里有人能帮上忙吗?
更新:抱歉,一些样本数据显然会对此有所帮助
player1参与的每一只手都有这样一行:
Dealt to player1 [4c Ac]我特别在"“和"”中查找以下所有内容
7h 2c 7h 2d 7h 2s 7c 2h 7c 2d 7c 2s 7d 2h 7d 2c 7d 2s 7s 2h 7s 2c 7s 2d
发布于 2015-02-06 05:30:44
你也许能够使用负面的lookaheads来实现你想要做的事情。
https://regex101.com/r/yK4oC7/2 (*表示匹配)
Dealt to player1 []
Dealt to player1 [7c 2c]
Dealt to player1 [7c 2h] *
Dealt to player1 [7d 7c]下面是正则表达式\[([72])([sdch]) (?\!\1)([72])(?\!\2)([sdch])的详细信息(在bash中,!是一个特殊字符,必须转义。因此,当mamy语言使用(?!....)执行负面先行时,bash似乎需要(?\!....)。
\[ - match literal [
([72]) - match 7 or 2 and capter as \1
([sdch]) - match s,d,c or h
(?!\1)([72]) - match a space followed by digit that's not the same as \1
and is 7 or 2
(?!\2)([sdch]) - match sdch where it's not the same as whichever of the
four was matched as \1编辑:我不使用bash,所以我不熟悉其中的细微差别,但是How to use regex negative lookahead的两个答案对于设计正确的语法应该很有用。
https://stackoverflow.com/questions/28329920
复制相似问题