Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

compare substring of two text

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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";
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading