정규식 후방탐색 에러가 나는 이유가 궁금합니다.
본문
에디트 플러스나 php preg_ 관련 라이브러리에서
(?<=) 관련 regex만 문제가 되네요.. 전방탐색은 잘 됩니다.
혹시 이유를 알고계신 분이 있으신가요??
아래 과정에서 발생한 문제입니다.
$str = [a,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,b,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23],[0,0,0,d,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,e,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,f,0,d,d,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,g,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
괄호 사이의 콤마를 기준으로 배열로 정리하려 함.
즉,
Array (
[0] => [a,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[1] => [0,b,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[2] => [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]
[3] => [0,0,0,d,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[4] => [0,0,0,0,e,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[5] => [0,0,0,0,0,f,0,d,d,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[6] => [0,0,0,0,0,0,g,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
)
와 같이 하기 위해
(?<=\]),(?=\[)
regex를 사용하려 하지만 에디트플러스나 php 관련 preg_ 함수에서도 잘 작동되지 않음
현재는 ,(?=\[) 전방탐색만 사용중.
후방탐색 (?<=\])이 에러나는 이유가 궁금합니다.
답변 1
아래 방법으로 하지않는 이유라도 있는가요?
preg_match_all("/(\[.*\])/U", $str, $match);
$myarr =$match[1];
print_r($myarr);