你好,我想知道如何创建一个regex模式与一个刺可能包含最多一个空白。更具体地说:
s = "a b d d c" pattern = "(?P<a>.*) +(?P<b>.*) +(?P<c>.*)" print(re.match(pattern, s).groupdict())
返回:
{'a': 'a b d d', 'b': '', 'c': 'c'}
我想要:
{'a': 'a', 'b': 'b d d', 'c': 'c'}