畢桳栠摩琠敨映捡獴 def match(pattern, input): m = re.compile(pattern).match(input) if m: return m.group(0) return False def test(pattern): match(pattern, 'Hello') == False match(pattern, 'Hello?') == 'Hello' match(pattern, 'Hello??') == 'Hello?' >>> pattern = r"(.*?)(?>> match(pattern, 'hello') False >>> match(pattern, 'hello?') 'hello?' >>> match(pattern, 'hello??') 'hello?' >>> match(pattern, 'hello?!') 'hello?' >>> match(pattern, 'hello!?') False >>> match(pattern, 'hello??!') 'hello?' >>> match(pattern, 'hello? lol?') 'hello?' >>>