p = re.compile('\d,\d,') s = p.findall('{{1,2,3},{3,4,5,6},{7,8}}')
코드에서는 1,2, 와 3,4, 를 검출하려고 하는건데요. \d,\d, 을 (\d,){2}와 같이 반복구조로 바꾸려고 하는데 출력결과가 1,2, 와 3,4 가 아니라 2, 와 4, 네요. 어떻게 하면 고칠수있을까요?
1. Python인가요? 2. Python2인가요, 아니면 3인가요? 이런 디테일들이 질문과 크게 상관 없을 때도 있지만, 상당히 중요한 경우도 있습니다. 질문할 때 미리 알려주면 좋겠지요.
레퍼런스(https://docs.python.org/2.7/library/re.html#re.findall or https://docs.python.org/3.8/library/re.html#re.findall )에서도 볼 수 있듯, re.findall은 pattern에 group이 있으면, group의 list를 반환합니다.
이럴 땐 그냥 non-capturing parentheses를 써 주면 해결됩니다: (?:\d,){2}
(?:\d,){2}
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
1. Python인가요?
1. Python인가요?
2. Python2인가요, 아니면 3인가요?
이런 디테일들이 질문과 크게 상관 없을 때도 있지만, 상당히 중요한 경우도 있습니다.
질문할 때 미리 알려주면 좋겠지요.
레퍼런스(https://docs.python.org/2.7/library/re.html#re.findall or https://docs.python.org/3.8/library/re.html#re.findall )에서도 볼 수 있듯, re.findall은 pattern에 group이 있으면, group의 list를 반환합니다.
이럴 땐 그냥 non-capturing parentheses를 써 주면 해결됩니다:
(?:\d,){2}
댓글 달기