<?php
$url = "http://<hostname>/p/Brand-Product-Name-6118-161-1-gallery.jpg";
preg_match_all('#(\d+)-(\d+)-\d+-gallery\.jpg$#',$url,$matches);
// Depends on how accurate you want to be. You can go with many choices like:
// preg_match_all('#http\://.*?/p/.*?(\d+)-(\d+)-\d+-.*\.jpg#',$url,$matches);
var_dump($matches);
/*
array(3) {
[0]=>
array(1) {
[0]=>
string(22) "6118-161-1-gallery.jpg"
}
[1]=>
array(1) {
[0]=>
string(4) "6118"
}
[2]=>
array(1) {
[0]=>
string(3) "161"
}
}
*/
1
solved Need Regular Expression for Format -xx-xxx-x- [closed]