Skip to content

Instantly share code, notes, and snippets.

@ivanrosolen
Created November 9, 2018 13:42
Show Gist options
  • Save ivanrosolen/2bd74b8db873ed57a979920e656cd8a7 to your computer and use it in GitHub Desktop.
Save ivanrosolen/2bd74b8db873ed57a979920e656cd8a7 to your computer and use it in GitHub Desktop.
Named Capturing Group REGEX
<?php
$regex = "/(?'group1'[0-9]+)_(?'group2'.+)_(?'group3'[0-9A-Z]+).(?'ext'.+)$/";
$files = [
'01_lero_1X.pdf',
'02_lerolero_13.pdf',
'03_1k_KK.pdf'
];
foreach ($files as $key => $name) {
preg_match($regex, $name, $matches);
print_r($matches);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment