I can not understand where was wrong. Help me please. Here is the text that actually contains newline characters (I deleted them so as not to clutter the text of the question):

<div id="p0" class="productContainer" style="width: 195px; margin-left: 10px; margin-bottom: 35px"><div class="title" style="font-size: 14px">AmazonBasics HDMI Input to D?</div><a href="#!product/1-B014I8UQJY"><div class="productBox colorTipContainer whiteDeals" id="pB0"><div class="productImageDiv"><div class="productImage"><img class="active " src="https://images-na.ssl-images-amazon.com/images/I/41-O%2BZoRjZL._SS180_.jpg" width="180px" height="180px"></div></div><div class="productSmallDescription" style="margin-left: 6px;"><span class="searchPrices"><div class="priceLegend productPriceTableSmall">Amazon: <span class="priceAmazon productPriceTableSmall" style="line-height: 13px;">?$ 6.59</span></div><div class="priceLegend productPriceTableSmall"><span class="priceAmazon productPriceTableSmall" style="line-height: 13px;">?</span></div><div class="priceLegend productPriceTableSmall"><span class="priceAmazon productPriceTableSmall" style="line-height: 13px;">?</span></div></span></div><span class="colorTip" style="width: 250px; top: -18px;"><span class="colorTipContent">AmazonBasics HDMI Input to DVI Output Adapter Cable - 6 Feet (Latest Standard)</span><span class="pointyTipShadow"></span><span class="pointyTip"></span></span></div></a></div><br><div style="clear: both;margin: 60px;text-align: center;"><a href="https://www.amazon.com/gp/search?keywords=AmazonBasics%20HDMI%20Input%20to%20DVI%20Output%20Adapter%20Cable%20-%206%20Feet%20(Latest%20Standard)" class=".tabTrack">>?Continue your search on Amazon?<</a></div></div></div></div></div> 

I use QT code:

 QString IS_TEST = "(?<=<div id=\"p0\" class=\"productContainer\").+(?=Continue your search on Amazon)"; QRegularExpression* re = new QRegularExpression(IS_TEST, QRegularExpression::MultilineOption); QRegularExpressionMatch match = re->match(site); if(match.hasMatch()) { qDebug() <<"НАШЛО"; } 
  • What result do you want to get? Give examples of suitable lines and inappropriate ones. HTML parsing is best done with specialized parsers, for example, use QXmlQuery services. In C ++ you can use the so-called. raw strings and do not escape double quotes inside. R"(... любой текст ...)" - mymedia
  • I want to get everything between <div id = "p0" class = "productContainer" and this one. Continue your search on Amazon - Madoka Magica
  • "HTML parsing is best done with specialized parsers," Maybe you're right just need to learn it and I worked with regulars. - Madoka Magica
  • Regular season itself seems to be correct - yrHeTaTeJlb
  • Yes, and your code gave me "FOUND". Write a sample code that can compile and reproduce the problem. - yrHeTaTeJlb

1 answer 1

Replace the QRegularExpression::MultilineOption flag, which changes the behavior of ^ (beginning of line) and $ (end of line) QRegularExpression::DotMatchesEverythingOption , with QRegularExpression::DotMatchesEverythingOption , which changes the point's behavior (makes it find line feed / carriage return characters).

Also .+ Replace with .+? to search for the nearest right Continue your search on Amazon .

In addition, (?<=a).+?(?=b) more efficiently rewritten as a(.+?)b , and then instead of getting the desired value through

 QRegularExpression re("<div\\s+id=\"p0\"\\s+class=\"productContainer\"(.+?)Continue your search on Amazon", QRegularExpression::DotMatchesEverythingOption); QRegularExpressionMatch match = re.match(site); if (match.hasMatch()) { QString day = match.captured(1); // Группа №1 содержит искомое значение } 
  • Yes, ATP really helped not here, but this question can also be considered the correct answer. I haven't checked QRegularExpression :: DotMatchesEverythingOption yet, but then later - Madoka Magica