給你在PHP的示例,但是該正則表達式可以用另一種語言被重用:
$urls = array(
'mywebsite.com/images/products/12345678_pit.jpg',
'mywebsite.com/images/products/23456789_foo.jpg',
'mywebsite.com/images/products/34567890_bar.jpg',
'mywebsite.com/images/products/12345678_piat_a2.jpg',
'mywebsite.com/images/products/45678901_baz_a2.jpg',
'mywebsite.com/images/products/56789012_qux_a2.jpg'
);
foreach($urls as $url) {
echo preg_replace(
'/products\/(\d{2})(\d*)_[a-z-]+(.*)\.jpg/i',
'zoomimage/$1/$1$2_var$3.jpg', $url) .'<br>';
}
// mywebsite.com/images/zoomimage/12/12345678_var.jpg
// mywebsite.com/images/zoomimage/23/23456789_var.jpg
// mywebsite.com/images/zoomimage/34/34567890_var.jpg
// mywebsite.com/images/zoomimage/12/12345678_var_a2.jpg
// mywebsite.com/images/zoomimage/45/45678901_var_a2.jpg
// mywebsite.com/images/zoomimage/56/56789012_var_a2.jpg
你在用什麼語言? – Toto
你的預算是多少?如果你希望我們做所有的工作,你不指望它是免費的,對吧? – h2ooooooo
詢問代碼的問題必須證明解決實際問題的最小努力,包括嘗試的代碼和遇到的問題 – HamZa