<?php $pattern = '/^[a-z]{5,8}_(\d{1,2})\.jpg$/'; $names = [ 'asd_1234.jpg', 'asdfg_12.jpg', 'asdfgj_72.jpg', 'as123_1.jpg', 'asdfg_.jpg', 'qweasdfgj_24.jpg', ]; foreach ($names as $entry) { if (preg_match($pattern, $entry, $matches)) { echo "{$entry}: ${matches[1]}\n"; } else { echo "{$entry} doesn't match\n"; } }
You have javascript disabled. You will not be able to edit any code.