Jump to content

PHP Regex + Grouping


razta

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/199003-php-regex-grouping/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.