[질문] 정규 표현식 관련 질문.

jwg286의 이미지

안녕하세요.

== 질문1 ==
http://en.wikipedia.org/wiki/Regular_Expression 보면 아래와 같은 내용이 있는데,

Quote:
A \n*, where n is a digit from 1 to 9, matches to zero or more iteration of the exact string what the expression enclosed in the n 'th left parenthesis and its pairing right parenthesis has been matched to. For example, "\(a??\)\1" matches to "abcbc" and "adede" but not "abcde".

여기서 "\(a??\)\1" 가 왜 "abcbc" 혹은 "adede" 는 되는데, "abcde" 는
안되는지 궁금합니다.

egrep 으로 테스트 해봐도, abcde 가 된다고 하더라도 찾았다는 메세지가 나오구요.. :'(

== 질문2 ==
"a\(b\)?c\1d" 와 같은 정규 표현식이 있다고 했을 때, 이 패턴은 acd 가 매치되는게 맞나요?

nachnine의 이미지

\1

은 backreference 라고 합니다.

( ) 로 묶어준 1번째 패턴을 다시 가리키는 거죠

abcbc -> () = bc , \1 = bc
adede -> () = de \1 = de

로 된겁니다

a가 괄호 바깥쪽으로 빠져야 할거 같은데 오타아닌가 모르겠네요