razta Posted April 19, 2010 Share Posted April 19, 2010 Hello, I am trying to match a regex and extract the data from the matched string that I want. I want to extract the Apache version only from the Apache website. So I am using the following raw sting to do the match: <li><a href="#apache22">2.2.15</a> (released 2010-03-06)</li> And the data I want from the above raw string is just the '2.2.15'. Here is the code related to this problem: // Match regex in grabbed HTML source preg_match('/<li><a\shref="#apache22">(\d\.\d\.\d?\d)<\/a>\s\(released\s\d\d\d\d-\d\d-\d\d\)<\/li>/', $grabPage, $regex_version); echo $regex_version[0]; I expected the above to output '2.2.15' instead it output '<li><a href="#apache22">2.2.15</a> (released 2010-03-06)</li>'. Any help appreciated. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
cags Posted April 19, 2010 Share Posted April 19, 2010 Capture group 0 always returns whatever string matched the entire pattern, therefore that is what is located in $regex_version[0]. The version number 2.2.15 should be contained within $regex_version[1]. Quote Link to comment Share on other sites More sharing options...
razta Posted April 19, 2010 Author Share Posted April 19, 2010 Something so simple yet fundamental. Thank you very much for your help! Quote Link to comment 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.