I'm trying to create a regular expression that would match a string. I am adding a multiple condition, starting with 'f', followed by any number of characters, followed by letter 'a' or the character '-', followed by one or more numeric characters and followed by the letter 'n'
The following examples should return true:
- f2a20n
- f2bfv-2009n
- f2-2000n
- f2bfv-2009na
So far I have researched php regular expression and created this code
$a = 'f2bfv-2009n';
$f_search = 'f';
$num_search = '[0-9]';
$or_search = '(a|-)';
$double_number_search = "^[0-9]{1,}$";
$n_search = 'n';
if(preg_match("/{$or_search}{$double_number_search}{$f_search}{$num_search}{$n_search}/i", $a)) {
echo 'true';
}
This should be true but its not