使用groups()
import re text = "Hello, my name is John Doe. I live in New York." match = re.search(r'\b(\w+)\b', text) if match: print("Match found: ", match.group()) print("Number of groups: ", len(match.groups())) else: print("No match found.")
使用groups()
import re text = "Hello, my name is John Doe. I live in New York." match = re.search(r'\b(\w+)\b', text) if match: print("Match found: ", match.group()) print("Number of groups: ", len(match.groups())) else: print("No match found.")