Python: Getting text of a Regex match -
i have regex match object in python. want text matched. if pattern '1.3', , search string 'abc123xyz', want '123'. how can that?
i know can use match.string[match.start():match.end()], find quite cumbersome (and in cases wasteful) such basic query.
is there simpler way?
you can use match object's group function, like:
match = re.search(r"1.3", "abc123xyz") if match: dosomethingwith(match.group(0)) to entire match. edit: thg435 points out, can omit 0 , call match.group().
addtional note: if pattern contains parentheses, can these submatches, passing 1, 2 , on group().