Reputation: 2785
How can I with regex in PHP make this
http://www.domain.com/path/to/image/ipsum_image.jpg
Match this and ignore the size part
http://www.domain.com/path/to/image/ipsum_image-300x200.jpg
Keep in mind that 300x200 can be anything, from 4charsx4chars to 1charx1char
Upvotes: 2
Views: 296
Reputation: 6529
$subject = 'http://www.domain.com/path/to/image/ipsum_image-300x200.jpg';
$result = preg_replace('&(-[0-9]{1,4}x[0-9]{1,4})&is', '', $subject);
echo $result;
Upvotes: 3
Reputation: 5856
$str= "http://www.domain.com/path/to/image/ipsum_image-300x200.jpg";
$regex= '/(\d{1,4})x(\d{1,4}).jpg$/i';
preg_match($regex, $str, $match, PREG_OFFSET_CAPTURE, 3);
print_r($match);
Upvotes: 0