IDLE 1.1.4
>>> import re
>>> some_text = 'alpha, beta,,,,gamma delta'
>>> re.split('[, ]+', some_text)
['alpha', 'beta', 'gamma', 'delta']
# when the pattern doesn't contain parentheses, the returned values
# only include matched substrings but separators.
>>> re.split('([, ]+)', some_text)
['alpha', ', ', 'beta', ',,,,', 'gamma', ' ', 'delta']
# returned values include separators and I can guess how it works.
>>> re.split('([, ])+', some_text)
['alpha', ' ', 'beta', ',', 'gamma', ' ', 'delta']
# Now I cannot even guess what is going on here.
질문>'([, ]+)'
및 '([, ])+'
차이는 무엇입니까? 반환 값에 어떤 영향을 줍니까?간의 매칭 패턴의 차이 '([,] +)'와 '([,]) +'
're.search()'와 일치시켜보고 일치하는 항목을 볼 수도 있습니다. 그룹과의'split' 행동은 여기에 추가적인 복잡성을 가져옵니다. – tripleee