I have two arrays like below
['*01***12*4**','0*****54*41*','***18*******','*2*7**3***1','***42*12*4**',...]
['128420120400','012189654700','321501481012','88114474111',...]
I want to compare the strings of two arrays without considering the stars and put the same codes in an array (the length of the codes in both arrays is 12)
In the example above, '***42*12*4**'and ‘128420120400‘codes are equal.
I use php (laravel)
>Solution :
One approach would be to use regular expressions, where each * placeholder in the masked string is replaced by \d, the latter which represents a single digit.
$mask = "***42*12*4**";
$input = "128420120400";
$regex = str_replace("*", "\d", $mask); // \d\d\d42\d12\d4\d\d
if (preg_match("/^" . $regex . "$/", $input)) {
echo "MATCH";
}