私はこの文字列を持っています
circle,4.5
square,3.1
circle,2.0
triangle,4.7,4.9
square,4.1
circle,4.3
図形の名前とその横にある2つの数字をキャプチャしたいとします。私はこれを試しました、そして私がその中に持っている問題についてコメントします:
>>> ma = re.search(r"(\w+)[,(\d+.\d+)]+", "Triangle,3.4,1.2")
>>> ma.group()
'Triangle,3.4,1.2'
>>> ma.group(1)
'Triangle'
>>> ma.group(2) ##Why is this happening ???
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
ma.group(2)
IndexError: no such group
角かっこ内にキャプチャグループを入れることはできないと思いますか?