fork download
  1. <?php
  2.  
  3. $filenames = array(
  4. 'Vacation (1).png',
  5. 'Vacation (Me and Mom) (2).png',
  6. 'Vacation (5) (3).png',
  7. );
  8.  
  9. foreach ( $filenames as $filename ) {
  10. if ( preg_match( '/^.*\((\d+)\)/s', $filename, $matches ) ) {
  11. var_dump($matches);
  12. } else {
  13. }
  14. }
  15.  
Success #stdin #stdout 0.04s 25896KB
stdin
Standard input is empty
stdout
array(2) {
  [0]=>
  string(12) "Vacation (1)"
  [1]=>
  string(1) "1"
}
array(2) {
  [0]=>
  string(25) "Vacation (Me and Mom) (2)"
  [1]=>
  string(1) "2"
}
array(2) {
  [0]=>
  string(16) "Vacation (5) (3)"
  [1]=>
  string(1) "3"
}