Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:43:37+00:00 2026-05-24T12:43:37+00:00

I have the following regex in a PHP script $total_matches = preg_match_all(‘{ <a\shref= (?<link>[^]+)

  • 0

I have the following regex in a PHP script

$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);

this regex seems to work fine when parsing the following (via php or using the parser at regexr.com (with the same options set for case insensitive, extended, treat line breaks as whitespace):

<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>

If I try to parse several matches in a row, it works fine also. However when I try parsing the full page these matches come from (I have permission to parse this)

http://www.mytheresa.com/us_en/new-arrivals/what-s-new-this-week-1.html?limit=12

the regex fails (I actually get a 500 error). I’ve tried increasing the backtrack limit using

ini_set('pcre.backtrack_limit',100000000);
ini_set('pcre.recursion_limit',100000000);

but this does not solve the problem. I am wondering what I am doing wrong that is causing the regex to fail via PHP when it seems to be valid, and match code on the relevant page. Fiddling with it seems to suggest the negative lookaheads (in conjunction with the page length) are causing problems, but I’m not sure how I screwed them up. I am running PHP 5.2.17.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:43:38+00:00Added an answer on May 24, 2026 at 12:43 pm

    You have made one of the classic blunders! Don’t use regex to parse HTML! It breaks regex! (This is right after “Never get involved in a land war in Asia” and “Never go in against a Sicilian when death is on the line.”).

    You should be using SimpleXML or DomDocument to parse this:

    $dom = new DomDocument();
    $dom->loadHTML( 'http://www.mytheresa.com/us_en/new-arrivals/'.
                     'what-s-new-this-week-1.html?limit=12' );
    
    $path = new DomXPath( $dom );
    // this query is based on the link you provided, not your regex
    $nodes = $path->evaluate( '//ul[class="products-grid first odd"]/li' );
    foreach( $nodes as $node )
    {
        // children 0 = anchor tag you're looking for initially.
        echo $node->children[0]->getAttribute("href");
        // iterate through the other children that way
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following regex expression to match html links: <a\s*href=['|](http:\/\/(.*?)\S['|]> it kind of
I have the following RegEx id=(.*?) | id=(.*?) The reason for this is I
I have the following regex: (?!^[&#]*$)^([A-Za-z0-9-'.,&@:?!()$#/\\]*)$ So allow A-Z, a-Z, 0-9, and these special
To outline: I have a parser that grabs Cell references using the following regex
In Python compiled regex patterns have a findall method that does the following: Return
I have this .NET regex: ^(?<prefix>([^]*))\s(?<attrgroup>(\([^\)]*\)))\s(?<suffix>([^]*))$ It properly matches the following strings: some prefix
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following situation. A main table and many other tables linked together with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.