Nuv Posted June 16, 2011 Share Posted June 16, 2011 I am trying to capture different fields i.e. img src,brand,model,year.shape and the dimensions (this field differs from 1 to 4) of each product(there are 3 products, if you notice the complete data i have displayed). If you notice the partial pattern i displayed below, you will notice that years have space gaps in between which is making my regex not to work. It is working till model though. How can i make it work for year too. (I was just testing where it stopped working thus my regex i displayed here isn't full and fetches data only till year.) Also, my other question is number of dimensions may differ from 1 to 4 like below all the 3 data products have 3 dimensions.How to capture it then ? Partial Pattern - <img src="images/dimensions/RoundSquareThA.gif" border="0" class="cover-thumb"> <p><strong>Important Note:</strong> Please be sure to check these suggested measurements with your spa.<br /> If you do not see your spa cover listed, you can measure for your dimensions.</p> </div> <div class="cover-specs"> <strong>Brand:</strong> <span class="values">Marquis</span><br /> <strong>Model:</strong> <span class="values">Mirage</span><br /> <strong>Year:</strong> <span class="values"> 1981 , 1982 , 1983 <br /> 1984 , 1985 , 1986 <br /> 1987 , 1988 , 1989 <br /> 1990 , 1991 </span><br /> <div style="border-top:1px solid #999; width:200px; margin:10px 0;"> </div> <strong>Shape:</strong> <span class="values">Rounded Square or Rectangle</span><br /> <strong>Dimension A:</strong> <span class="values">78.5</span><br /> <strong>Dimension B:</strong> <span class="values">85.5</span><br /> <strong>Dimension C:</strong> <span class="values">1.5</span><br /> <div style="small">*Spa dimensions units are measured in inches.</div> </div> Regex i am using $regex = "~<img\s+src=\"(.*?)\"\s+border=\"0\"\s+class=\"cover-thumb\">\s+<p><strong>Important\s+Note:</strong>\s+Please\s+be\s+sure\s+to\s+check\s+these\s+suggested\s+measurements\s+with\s+your\s+spa.<br\s+/>\s+If\s+you\s+do\s+not\s+see\s+your\s+spa\s+cover\s+listed,\s+you\s+can\s+measure\s+for\s+your\s+dimensions.</p>\s+</div>\s+<div\s+class=\"cover-specs\">\s+<strong>Brand:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>\s+<strong>Model:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>\s+<strong>Year:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>~"; preg_match_all($regex, $result, $out); Complete Data text <div class="cover-popup"> <div class="cover-popup-header"><h3>SELECTION BY SPA BRAND</h3></div> <div class="cover-results"> <p>We found the following results for your search<br /> Click on the result that best matches your cover.</p> <div class="cover-image"> <img src="images/dimensions/RoundSquareThA.gif" border="0" class="cover-thumb"> <p><strong>Important Note:</strong> Please be sure to check these suggested measurements with your spa.<br /> If you do not see your spa cover listed, you can measure for your dimensions.</p> </div> <div class="cover-specs"> <strong>Brand:</strong> <span class="values">Marquis</span><br /> <strong>Model:</strong> <span class="values">Mirage</span><br /> <strong>Year:</strong> <span class="values"> 1993 , 1994 , 1995 <br /> </span><br /> <div style="border-top:1px solid #999; width:200px; margin:10px 0;"> </div> <strong>Shape:</strong> <span class="values">Rounded Square or Rectangle</span><br /> <strong>Dimension A:</strong> <span class="values">74.75</span><br /> <strong>Dimension B:</strong> <span class="values">82.75</span><br /> <strong>Dimension C:</strong> <span class="values">6.75</span><br /> <div style="small">*Spa dimensions units are measured in inches.</div> </div> <div style="width:235px; float:left; margin-top:40px;" id="black"> <a href="rounded-square-spa-cover.php?custtext0=Marquis&custtext1=Mirage&custtext2=1993&custtext4=74.75&custtext5=82.75&custtext6=6.75&custtext7=&custtext8=&custtext9=&custtext10=&custtext11=&custtext13=3&custtext14=8"> <img src="images/select-this-cover.jpg" border="0"> </a> <p style="text-align:center; margin-top:15px; color:#000;">Not finding your dimensions?<br /> <a href="#" class="close" onclick="$.prettyPhoto.close(); return false;">Click here</a> to select by Spa Shape.</p> </div> <div style="height:20px; clear:both;"></div> <div class="cover-image"> <img src="images/dimensions/RoundSquareThA.gif" border="0" class="cover-thumb"> <p><strong>Important Note:</strong> Please be sure to check these suggested measurements with your spa.<br /> If you do not see your spa cover listed, you can measure for your dimensions.</p> </div> <div class="cover-specs"> <strong>Brand:</strong> <span class="values">Marquis</span><br /> <strong>Model:</strong> <span class="values">Mirage</span><br /> <strong>Year:</strong> <span class="values"> 1996 , 1997 , 1998 <br /> 1999 </span><br /> <div style="border-top:1px solid #999; width:200px; margin:10px 0;"> </div> <strong>Shape:</strong> <span class="values">Rounded Square or Rectangle</span><br /> <strong>Dimension A:</strong> <span class="values">75</span><br /> <strong>Dimension B:</strong> <span class="values">83</span><br /> <strong>Dimension C:</strong> <span class="values">8</span><br /> <div style="small">*Spa dimensions units are measured in inches.</div> </div> <div style="width:235px; float:left; margin-top:40px;" id="black"> <a href="rounded-square-spa-cover.php?custtext0=Marquis&custtext1=Mirage&custtext2=1996&custtext4=75&custtext5=83&custtext6=8&custtext7=&custtext8=&custtext9=&custtext10=&custtext11=&custtext13=4&custtext14=8"> <img src="images/select-this-cover.jpg" border="0"> </a> <p style="text-align:center; margin-top:15px; color:#000;">Not finding your dimensions?<br /> <a href="#" class="close" onclick="$.prettyPhoto.close(); return false;">Click here</a> to select by Spa Shape.</p> </div> <div style="height:20px; clear:both;"></div> <div class="cover-image"> <img src="images/dimensions/RoundSquareThA.gif" border="0" class="cover-thumb"> <p><strong>Important Note:</strong> Please be sure to check these suggested measurements with your spa.<br /> If you do not see your spa cover listed, you can measure for your dimensions.</p> </div> <div class="cover-specs"> <strong>Brand:</strong> <span class="values">Marquis</span><br /> <strong>Model:</strong> <span class="values">Mirage</span><br /> <strong>Year:</strong> <span class="values"> 1981 , 1982 , 1983 <br /> 1984 , 1985 , 1986 <br /> 1987 , 1988 , 1989 <br /> 1990 , 1991 </span><br /> <div style="border-top:1px solid #999; width:200px; margin:10px 0;"> </div> <strong>Shape:</strong> <span class="values">Rounded Square or Rectangle</span><br /> <strong>Dimension A:</strong> <span class="values">78.5</span><br /> <strong>Dimension B:</strong> <span class="values">85.5</span><br /> <strong>Dimension C:</strong> <span class="values">1.5</span><br /> <div style="small">*Spa dimensions units are measured in inches.</div> </div> <div style="width:235px; float:left; margin-top:40px;" id="black"> <a href="rounded-square-spa-cover.php?custtext0=Marquis&custtext1=Mirage&custtext2=1981&custtext4=78.5&custtext5=85.5&custtext6=1.5&custtext7=&custtext8=&custtext9=&custtext10=&custtext11=&custtext13=4&custtext14=8"> <img src="images/select-this-cover.jpg" border="0"> </a> <p style="text-align:center; margin-top:15px; color:#000;">Not finding your dimensions?<br /> <a href="#" class="close" onclick="$.prettyPhoto.close(); return false;">Click here</a> to select by Spa Shape.</p> </div> <div style="height:20px; clear:both;"></div> </div> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/ Share on other sites More sharing options...
cags Posted June 16, 2011 Share Posted June 16, 2011 Asking a question which involves both regular expressions and HTML in the same post is pretty much asking for a grilling, it's generally considered a big fat no-no as you can't accurately model HTML syntax with regular expressions. That being said, if the input url is consistent enough there is nothing to stop you actually applying a pattern to it (with varying degree of success). Your pattern is failing because by default the . character does not match newline characters. You can get around that immediate problem by adding the s modifier to the end of your pattern, after the closing delimiter, which in your case is a tilde (~). With regards to your second question, regex doesn't cope well with variable numbers of matches. Your best bet would be to write a single capture group that would encompasses all the dimensions, and then write a second pattern that can be used on the result of the first to extract the individual pieces of information that you are after. Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1230519 Share on other sites More sharing options...
Nuv Posted June 16, 2011 Author Share Posted June 16, 2011 Yeah during my research i found out that i can't accurately model HTML syntax with regular expressions like you said. Funny answer over here. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?page=1&tab=votes#tab-top First answer is a must read if interested. Secondly i used 's' and i got the years atleast. I will think of other solutions for variable numbers of matches. Thankyou Cags. Really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1230528 Share on other sites More sharing options...
cags Posted June 16, 2011 Share Posted June 16, 2011 That is rather an amusing reply, I up voted it a long time ago It does annoy me though when people blanket throw hissy fits just because you use html and regex in the same post, sometimes it is perfectly valid. Having said that you'd probably be better off using something like simplexml to at least fetch the cover-specs divs from the document. Not sure how you'd fetch the actual details using it, but once you have a single node you could run multiple regexs against it to get the individual values. It would also be a lot easier to read if you had multiple ones rather than the behemoth you currently have. $brandPattern = '~<strong>Brand:</strong> <span class="values">([^<]+)</span><br />~'; // etc ... $dimensionsPattern = '~<strong>Dimension ([A-D]):</strong> <span class="values">(\d+(?:\.\d{1,2})?)</span>~'; Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1230544 Share on other sites More sharing options...
Nuv Posted June 16, 2011 Author Share Posted June 16, 2011 I know it won't be clean but i can just count the number of word "Dimensions" in the data and then use appropriate regex using if elses. What do you think ? Also, is something wrong with my regex ? I am trying to capture the src for the image however the result is unexpected.There should be 3 values. However its printing only 1 value.Moreover it should only print the src and not rest of the things ? [1] => Array ( [0] => images/dimensions/RoundSquareThA.gif [1] => images/select-this-cover.jpg" border="0"> Not finding your dimensions? Click here to select by Spa Shape. Not finding your dimensions? Click here to select by Spa Shape. My new regex(its the same,just added 's') $regex = "~\s+<img\s+src=\"(.*?)\"\s+border=\"0\"\s+class=\"cover-thumb\">\s+<p><strong>Important\s+Note:</strong>\s+Please\s+be\s+sure\s+to\s+check\s+these\s+suggested\s+measurements\s+with\s+your\s+spa.<br\s+/>\s+If\s+you\s+do\s+not\s+see\s+your\s+spa\s+cover\s+listed,\s+you\s+can\s+measure\s+for\s+your\s+dimensions.</p>\s+</div>\s+<div\s+class=\"cover-specs\">\s+<strong>Brand:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>\s+<strong>Model:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>\s+<strong>Year:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>\s+<div\s+style=\"border-top:1px\s+solid\s+#999;\s+width:200px;\s+margin:10px\s+0;\">\s+</div>\s+<strong>Shape:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>\s+<strong>Dimension\s+A:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>\s+<strong>Dimension\s+B:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>\s+<strong>Dimension\s+C:</strong>\s+<span\s+class=\"values\">(.*?)</span><br\s+/>~s"; Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1230552 Share on other sites More sharing options...
cags Posted June 16, 2011 Share Posted June 16, 2011 It's very hard to say, your pattern is far to large to be readable even in the slightest, if you insist on doing it all in one pattern (which I'm not sure I see the point of), then at least look into the x modifier so you can attempt to make it partially readable. Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1230565 Share on other sites More sharing options...
Nuv Posted June 16, 2011 Author Share Posted June 16, 2011 I understand. However i did nothing but 2 things. 1. I replaced the white space,line breaks with '\s+' 2. Whichever data i wanted i used (.*?) in place of actual data. I've just started, Mastering Regular Expressions 3 days ago. So don't know much about Regular Expressions. Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1230572 Share on other sites More sharing options...
xyph Posted June 16, 2011 Share Posted June 16, 2011 In your sample data, there's no unique image per entry, so I wasn't sure what one you wanted. RegEx is bad for parsing HTML, but if it's a static format it is possible. It's a slow RegEx, with lots of backtracking, and I had to do some post-processing to the data returned, but it works! <?php $expr = '%<img\ssrc="images/dimensions/([^"]++)"[^>]*+>.*? <strong>Brand:</strong>\s<span\sclass="values">([^<]++)</span><br\s/>\s++ <strong>Model:</strong>\s<span\sclass="values">([^<]++)</span><br\s/>\s++ <strong>Year:</strong>\s<span\sclass="values">\s++([^<]++).*? <strong>Shape:</strong>\s<span\sclass="values">([^<]++)</span><br\s/>\s++ <strong>(.*?)<div\sstyle="small">\*Spa%sx'; $subject = getData(); preg_match_all( $expr, $subject, $matches, PREG_SET_ORDER ); foreach( $matches as $match ) { echo 'Brand: '.$match[2].'<br>'; echo 'Model: '.$match[3].'<br>'; $match[4] = trim( str_replace( array(' ',"\r","\n"), '', $match[4] ) ); echo 'Years: '.$match[4].'<br>'; echo 'Shape: '.$match[5].'<br>'; $dims = explode("\n",strip_tags(trim($match[6]))); foreach( $dims as &$dim ) $dim = trim($dim); $match[6] = implode(',',$dims); echo 'Dimensions: '.$match[6].'<br>'; echo 'Image: '.$match[1].'<br><br>'; } function getData() { return '<div class="cover-popup"> <div class="cover-popup-header"><h3>SELECTION BY SPA BRAND</h3></div> <div class="cover-results"> <p>We found the following results for your search<br /> Click on the result that best matches your cover.</p> <div class="cover-image"> <img src="images/dimensions/RoundSquareThA.gif" border="0" class="cover-thumb"> <p><strong>Important Note:</strong> Please be sure to check these suggested measurements with your spa.<br /> If you do not see your spa cover listed, you can measure for your dimensions.</p> </div> <div class="cover-specs"> <strong>Brand:</strong> <span class="values">Marquis</span><br /> <strong>Model:</strong> <span class="values">Mirage</span><br /> <strong>Year:</strong> <span class="values"> 1993 , 1994 , 1995 <br /> </span><br /> <div style="border-top:1px solid #999; width:200px; margin:10px 0;"> </div> <strong>Shape:</strong> <span class="values">Rounded Square or Rectangle</span><br /> <strong>Dimension A:</strong> <span class="values">74.75</span><br /> <strong>Dimension B:</strong> <span class="values">82.75</span><br /> <strong>Dimension C:</strong> <span class="values">6.75</span><br /> <div style="small">*Spa dimensions units are measured in inches.</div> </div> <div style="width:235px; float:left; margin-top:40px;" id="black"> <a href="rounded-square-spa-cover.php?custtext0=Marquis&custtext1=Mirage&custtext2=1993&custtext4=74.75&custtext5=82.75&custtext6=6.75&custtext7=&custtext8=&custtext9=&custtext10=&custtext11=&custtext13=3&custtext14=8"> <img src="images/select-this-cover.jpg" border="0"> </a> <p style="text-align:center; margin-top:15px; color:#000;">Not finding your dimensions?<br /> <a href="#" class="close" onclick="$.prettyPhoto.close(); return false;">Click here</a> to select by Spa Shape.</p> </div> <div style="height:20px; clear:both;"></div> <div class="cover-image"> <img src="images/dimensions/RoundSquareThA.gif" border="0" class="cover-thumb"> <p><strong>Important Note:</strong> Please be sure to check these suggested measurements with your spa.<br /> If you do not see your spa cover listed, you can measure for your dimensions.</p> </div> <div class="cover-specs"> <strong>Brand:</strong> <span class="values">Marquis</span><br /> <strong>Model:</strong> <span class="values">Mirage</span><br /> <strong>Year:</strong> <span class="values"> 1996 , 1997 , 1998 <br /> 1999 </span><br /> <div style="border-top:1px solid #999; width:200px; margin:10px 0;"> </div> <strong>Shape:</strong> <span class="values">Rounded Square or Rectangle</span><br /> <strong>Dimension A:</strong> <span class="values">75</span><br /> <strong>Dimension B:</strong> <span class="values">83</span><br /> <strong>Dimension C:</strong> <span class="values">8</span><br /> <div style="small">*Spa dimensions units are measured in inches.</div> </div> <div style="width:235px; float:left; margin-top:40px;" id="black"> <a href="rounded-square-spa-cover.php?custtext0=Marquis&custtext1=Mirage&custtext2=1996&custtext4=75&custtext5=83&custtext6=8&custtext7=&custtext8=&custtext9=&custtext10=&custtext11=&custtext13=4&custtext14=8"> <img src="images/select-this-cover.jpg" border="0"> </a> <p style="text-align:center; margin-top:15px; color:#000;">Not finding your dimensions?<br /> <a href="#" class="close" onclick="$.prettyPhoto.close(); return false;">Click here</a> to select by Spa Shape.</p> </div> <div style="height:20px; clear:both;"></div> <div class="cover-image"> <img src="images/dimensions/RoundSquareThA.gif" border="0" class="cover-thumb"> <p><strong>Important Note:</strong> Please be sure to check these suggested measurements with your spa.<br /> If you do not see your spa cover listed, you can measure for your dimensions.</p> </div> <div class="cover-specs"> <strong>Brand:</strong> <span class="values">Marquis</span><br /> <strong>Model:</strong> <span class="values">Mirage</span><br /> <strong>Year:</strong> <span class="values"> 1981 , 1982 , 1983 <br /> 1984 , 1985 , 1986 <br /> 1987 , 1988 , 1989 <br /> 1990 , 1991 </span><br /> <div style="border-top:1px solid #999; width:200px; margin:10px 0;"> </div> <strong>Shape:</strong> <span class="values">Rounded Square or Rectangle</span><br /> <strong>Dimension A:</strong> <span class="values">78.5</span><br /> <strong>Dimension B:</strong> <span class="values">85.5</span><br /> <strong>Dimension C:</strong> <span class="values">1.5</span><br /> <div style="small">*Spa dimensions units are measured in inches.</div> </div> <div style="width:235px; float:left; margin-top:40px;" id="black"> <a href="rounded-square-spa-cover.php?custtext0=Marquis&custtext1=Mirage&custtext2=1981&custtext4=78.5&custtext5=85.5&custtext6=1.5&custtext7=&custtext8=&custtext9=&custtext10=&custtext11=&custtext13=4&custtext14=8"> <img src="images/select-this-cover.jpg" border="0"> </a> <p style="text-align:center; margin-top:15px; color:#000;">Not finding your dimensions?<br /> <a href="#" class="close" onclick="$.prettyPhoto.close(); return false;">Click here</a> to select by Spa Shape.</p> </div> <div style="height:20px; clear:both;"></div> </div> </div> </div>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1230779 Share on other sites More sharing options...
Nuv Posted June 17, 2011 Author Share Posted June 17, 2011 Work flawlessly. Now i need to take out my book and understand why you used $expr = '%<img\ssrc="images/dimensions/([^"]++)"[^>]*+>.*? <strong>Brand:</strong>\s<span\sclass="values">([^<]++)</span><br\s/>\s++ <strong>Model:</strong>\s<span\sclass="values">([^<]++)</span><br\s/>\s++ <strong>Year:</strong>\s<span\sclass="values">\s++([^<]++).*? <strong>Shape:</strong>\s<span\sclass="values">([^<]++)</span><br\s/>\s++ <strong>(.*?)<div\sstyle="small">\*Spa%sx'; Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1230927 Share on other sites More sharing options...
xyph Posted June 17, 2011 Share Posted June 17, 2011 Here's it in English, quite long though <img\ssrc="images/dimensions/([^"]++)"[^>]*+>.*? <strong>Brand:</strong>\s<span\sclass="values">([^<]++)</span><br\s/>\s++ <strong>Model:</strong>\s<span\sclass="values">([^<]++)</span><br\s/>\s++ <strong>Year:</strong>\s<span\sclass="values">\s++([^<]++).*? <strong>Shape:</strong>\s<span\sclass="values">([^<]++)</span><br\s/>\s++ <strong>(.*?)<div\sstyle="small">\*Spa Options: dot matches newline; free-spacing Match the characters “<img” literally «<img» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “src="images/dimensions/” literally «src="images/dimensions/» Match the regular expression below and capture its match into backreference number 1 «([^"]++)» Match any character that is NOT a “"” «[^"]++» Between one and unlimited times, as many times as possible, without giving back (possessive) «++» Match the character “"” literally «"» Match any character that is NOT a “>” «[^>]*+» Between zero and unlimited times, as many times as possible, without giving back (possessive) «*+» Match the character “>” literally «>» Match any single character «.*?» Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?» Match the characters “<strong>Brand:</strong>” literally «<strong>Brand:</strong>» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “<span” literally «<span» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “class="values">” literally «class="values">» Match the regular expression below and capture its match into backreference number 2 «([^<]++)» Match any character that is NOT a “<” «[^<]++» Between one and unlimited times, as many times as possible, without giving back (possessive) «++» Match the characters “</span><br” literally «</span><br» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “/>” literally «/>» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s++» Between one and unlimited times, as many times as possible, without giving back (possessive) «++» Match the characters “<strong>Model:</strong>” literally «<strong>Model:</strong>» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “<span” literally «<span» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “class="values">” literally «class="values">» Match the regular expression below and capture its match into backreference number 3 «([^<]++)» Match any character that is NOT a “<” «[^<]++» Between one and unlimited times, as many times as possible, without giving back (possessive) «++» Match the characters “</span><br” literally «</span><br» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “/>” literally «/>» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s++» Between one and unlimited times, as many times as possible, without giving back (possessive) «++» Match the characters “<strong>Year:</strong>” literally «<strong>Year:</strong>» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “<span” literally «<span» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “class="values">” literally «class="values">» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s++» Between one and unlimited times, as many times as possible, without giving back (possessive) «++» Match the regular expression below and capture its match into backreference number 4 «([^<]++)» Match any character that is NOT a “<” «[^<]++» Between one and unlimited times, as many times as possible, without giving back (possessive) «++» Match any single character «.*?» Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?» Match the characters “<strong>Shape:</strong>” literally «<strong>Shape:</strong>» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “<span” literally «<span» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “class="values">” literally «class="values">» Match the regular expression below and capture its match into backreference number 5 «([^<]++)» Match any character that is NOT a “<” «[^<]++» Between one and unlimited times, as many times as possible, without giving back (possessive) «++» Match the characters “</span><br” literally «</span><br» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “/>” literally «/>» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s++» Between one and unlimited times, as many times as possible, without giving back (possessive) «++» Match the characters “<strong>” literally «<strong>» Match the regular expression below and capture its match into backreference number 6 «(.*?)» Match any single character «.*?» Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?» Match the characters “<div” literally «<div» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s» Match the characters “style="small">” literally «style="small">» Match the character “*” literally «\*» Match the characters “Spa” literally «Spa» Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1231069 Share on other sites More sharing options...
Nuv Posted June 19, 2011 Author Share Posted June 19, 2011 Got it ! Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/239518-regex-with-variable-number-of-fields/#findComment-1231889 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.