I have a PHP file that redirects the user to the right user manual, depending on the link they clicked on. Since we have a lot of manuals (some are former versions, we need to match with the latest), I'm forced to use a REGEX to find what I want.
Let's use fruits for example. In store, we have manual names that can look like that :
$manuals = [
'dc-cn-13apple-frv4-5.pdf',
'dc-cn-33_banana-strawberryv10-108.pdf',
'dc-cn-32peachenv10-125.pdf',
'dc-cn-23lemoncoconutwatermelonitv09-130.pdf'
];
So there's a lot of possible combination, what's important is that they always start with 'dc-cn-', then a 2 digits number that's important for us (it's like the reference of the fruit).
It continues with some words to describe the fruit followed immediately by 2 letters to know in which language the manual is, and a 'v08' or 'v10' to know the version. Sometimes those 2 letters and numbers for the version come with a dash (like '-frv4').
Finally, they always end with a random 3 digits number (automatically given by the CMS we use), followed by '.pdf'.
I tried to manipulate my array like this:
foreach ($manuals as $manual) {
if(preg_match('/^[0-9][0-9][\.]pdf$/', $manual)) {
echo 'OK';
}
}
But so far my REGEX doesn't match anything and I really feel I have no clue of what I'm doing.
It would really help me to be able to inspect the first number ('dc-cn-32', 'dc-cn-13'), the 2 letters at the end of the word ('-frv4', 'peachenv10' or 'melonitv09-130.pdf'), and the 3 last digits ('melonitv09-130.pdf').
Then I would preg_split it all and start to compare.
ryis identified as the lang code. - Wiktor Stribiżew