나는, 확장 PHP 스크립트에서 다음 정규식PHP의 preg_match_all()을 사용하여 기능적인 정규 표현식이 실패하는 이유는 무엇입니까?
$total_matches = preg_match_all('{
<a\shref="
(?<link>[^"]+)
"(?:(?!src=).)+src="
(?<image>[^"]+)
(?:(?!designer-name">).)+designer-name">
(?<brand>[^<]+)
(?:(?!title=).)+title="
(?<title>((?!">).)+)
(?:(?!"price">).)+"price">\$
(?<price>[\d.,]+)
}xsi',$output,$all_matches,PREG_SET_ORDER);
이 정규식은 PHP를 통해 (다음 또는 대소 문자를 구분 설정 같은 옵션 (regexr.com에서 파서를 사용하여 구문 분석 할 때 잘 작동하는 것 같다있다 , 치료 라인)의 공백으로 나눈 것. 난이 경기에서 온 전체 페이지를 구문 분석 할 때
<a href="http://www.mytheresa.com/us_en/dordogne-120-sandals.html" title=
"DORDOGNE 120 PLATEAU SANDALEN" class="product-image">
<img class="image1st" src= "http://mytheresaimages.s3.amazonaws.com/catalog/product/cache/common/product_114114/small_ image/230x260/9df78eab33525d08d6e5fb8d27136e95/P/0/P00027794-DORDOGNE-120-PLATEAU-SANDALEN-STANDARD.jpg"
width="230" height="260"
alt= "Christian Louboutin - DORDOGNE 120 SANDALS - mytheresa.com GmbH"
title= "Christian Louboutin - DORDOGNE 120 SANDALS - mytheresa.com GmbH" />
<img class="image2nd" src= "http://mytheresaimages.s3.amazonaws.com/catalog/product/cache/common/product_114114/image/230x260/9df78eab33525d08d6e5fb8d27136e95/P/0/P00027794-DORDOGNE-120-PLATEAU-SANDALEN-DETAIL_2.jpg"
width="230" height="260" alt=
"Christian Louboutin - DORDOGNE 120 SANDALS - mytheresa.com GmbH" title=
"Christian Louboutin - DORDOGNE 120 SANDALS - mytheresa.com GmbH" /> <span class=
"availability"><strong>available sizes</strong><br /></span></a>
<div style="margin-left: 2em" class="available-sizes">
<h2 class="designer-name">Christian Louboutin</h2>
<div class="product-buttons">
<div class="product-button">
NEW ARRIVAL
</div>
<div class="clearer"></div>
</div>
<h3 class="product-name"><a href=
"http://www.mytheresa.com/us_en/dordogne-120-sandals.html" title=
"DORDOGNE 120 SANDALS">DORDOGNE 120 SANDALS</a></h3>
<div class="price-box">
<span class="regular-price" id="product-price-114114"><span class=
"price">$805.00</span></span>
</div>
내가 연속으로 여러 일치 구문 분석하려고하면, 그것은 잘 또한 작동하지만 (내가 가진 동등한 권한 se this)
http://www.mytheresa.com/us_en/new-arrivals/what-s-new-this-week-1.html?limit=12
정규식이 실패합니다 (실제로 500 오류가 발생 함).
ini_set('pcre.backtrack_limit',100000000);
ini_set('pcre.recursion_limit',100000000);
을 사용하여 역 추적 제한을 늘리려고했지만 문제가 해결되지 않습니다. PHP가 올바른 것으로 보이고 관련 페이지에서 일치하는 코드가 나오면 정규 표현식이 실패하는 원인이 무엇인지 궁금합니다. 그것과 함께 비웃는 것은 부정적인 lookaheads (페이지 길이와 함께)가 문제를 일으키는 것을 제안하는 것처럼 보이지만, 나는 그들을 어떻게 망쳤는지 잘 모르겠습니다. PHP 5.2.17을 실행하고 있습니다.
및 사용 자체를 제시 수 있을까? –
또한'PCRE_VERSION' 상수를 확인하십시오. 합리적으로 구식이라면, 업데이트 된'libpcre'를 설치하십시오. '(?! ..). +)'어설 션은 아마도 비싸다. regex를 재 작업하거나 preg_replace_callback으로 분리하지 않으려면 phpQuery 또는 QueryPath와 같은 html 툴킷을 사용하여 추출하기 쉽고 (대개는 느리지는 않음) 추출하는 것이 좋습니다. – mario
@mario 내 PCRE_VERSION은 8.02 2010-03-19입니다. 이전 버전 (4 버전이 오래되었습니다)으로 사용할 수 있는지 확실하지 않습니다. 정규식을 다시 작성해야 할 수도 있습니다. 나는 선견지명이 비싸다는 것에 놀랐지 만 당신이 옳다고 생각합니다. 나는 정규식을 재 작업 할 수 없다면 phpQuery와 QueryPath를 살펴볼 것이다. – jela