Jump to content

is there a way to compare two strings, and generate a universal regex expresion


jjk2

Recommended Posts

Depends.  Are you just trying see what's in common from the beginning to X or, are you trying to compare all common characters?  Is the end always a number?

 

For the first part you could use something like:

 

$s1 = "apple1";
$s2 = "apple2";
$i = 0;
$temp = "";
while($s1[$i] != null)
{
   if($s1[$i] == $s2[$i])
   {
      $temp .= $s1[$i];
   }
   $i++;
}

echo $temp;
?>

well for example take URL

 

$d = "www.youtube.com/watch?v=AWm2zGTZBM0&feature=topvideos";
$d1 = "www.youtube.com/watch?v=vasdf32v&feature=featured";

a regex should be generated that would match that structure.

 

for instance it should out put $regex

"/www.youtube.com/watch?v=[a-zA-Z0-9]&feature=[a-z]/i

is it assured that the two examples given to the function you want to make will have everything that is possible to be different be different? otherwise this will not be possible, as it cannot possibly know what elements happen to be the same with the examples, and might in another case be different.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.