Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีได้จำนวน capture groups ใน Python Regular Expression

ใช้ regex ได้จำนวน captured groups ในสตริงที่กำหนด

ตัวอย่าง

import re
m = re.match(r"(\d)(\d)(\d)", "632")
print(len(m.groups()))

ผลลัพธ์

3