I'm sure this has already been asked and answered, but I honestly couldn't find my answer after searching for quite a bit and reading Regex Tutorial. What I'm looking to do is match a string that has the same characters and length as another string. For example, a string "abcde" would match "edcba" but would not match "abcdf" or "aabbc" or "abc".
Here is my test code with the closest I've come up with that uses a character class, but what I can't figure out is how to get regex to basically iterate through each character in the class once starting at the beginning of the match string:
$string = 'abcde';
$array = array('edcba','eeeee','fghij','fedcba','qqq','cbaed','cba');
foreach ($array as $match)
{
if (preg_match("/[$string]/i",$match))
echo "TRUE -> $match";
else
echo "FALSE -> $match";
}
Which gives the result:
TRUE -> edcba
TRUE -> eeeee
FALSE -> fghij
TRUE -> fedcba
FALSE -> qqq
TRUE -> cbaed
TRUE -> cba
When what I really want is:
TRUE -> edcba
FALSE -> eeeee
FALSE -> fghij
FALSE -> fedcba
FALSE -> qqq
TRUE -> cbaed
FALSE -> cba