我尝试解析分隔列表,但只获取第一个元素。这是我的代码:
point = Literal('.')
e = CaselessLiteral('E')
plusorminus = Literal('+') | Literal('-')
number = Word(nums)
integer = Combine( Optional(plusorminus) + number )
floatnumber = Combine( integer +
Optional( point + Optional(number) ) +
Optional( e + integer )
)
x = Word("0-100") + Suppress("(") + floatnumber + Suppress(")")
y = delimitedList(x)
text = "1(39.75), 2(39.75), 3(39.75), 4(39.75)"
try:
match = y.searchString(text)
except ParseException as pe:
print ("Did not Match: ", pe)
print ("results:", match)
导致: ('结果:',([([' 1',' 39.75'],{})],{}))
我期待括号前的每个数字,以及括号中的数字。
有人可以帮我这个吗? 提前致谢。