由于某些原因,pyparsing没有对我的字符串进行嵌套列表:
rank = oneOf("2 3 4 5 6 7 8 9 T J Q K A")
suit = oneOf("h c d s")
card = rank + Optional(suit)
suit_filter = oneOf("z o")
hand = card + card + Optional(suit_filter)
greater = Literal("+")
through = Literal("-")
series = hand + Optional(greater | through + hand)
series_split = Literal(",")
hand_range = series + ZeroOrMore(series_split + series)
hand_range.parseString('22+,AKo-ATo,KQz')
>> ['2', '2', '+', ',', 'A', 'K', 'o', '-', 'A', 'T', 'o', ',', 'K', 'Q', 'z']
我不确定为什么pyparsing没有将22+、AKo-ATo和KQz(或更深层次的任何内容)创建为列表。我错过了什么?
invRegex.py
链接已经失效了。 - shuttle87