개인적으로 두 정규식을 결합하지 않는 것이 좋습니다. 나는 두 개의 URL 패턴을 가지고 있다고 생각합니다.
url(r'^input/?$', input, name="input"),
url(r'^input/index.html?$', input),
보다 읽기 쉽습니다. 당신이 두 가지를 결합하려는 경우
그러나 비 캡처 괄호를 사용할 수 있습니다 도움이 될 수 있습니다
r'^input(?:/(?:index.html?)?)?$'
빠른 예를 설명 :
>>> import re
>>> # first try the regex with capturing parentheses
>>> capturing=r'^input(/(index.html?)?)?$'
>>> # Django passes the two matching strings to the input view, causing the type error
>>> print re.match(capturing, "input/index.html").groups()
('/index.html', 'index.html')
>>> # repeat with non capturing parentheses
>>> non_capturing=r'^input(?:/(?:index.html?)?)?$'
>>> print re.match(non_capturing, "input/index.html").groups()
()
더의 Regular Expression Advanced Syntax Reference 페이지를 참조하십시오 정보.