protected function deduplicateCompressionPattern($matches, &$pattern)
    {
      $tmp_matches = $matches;
      
      $first_match = array_shift($tmp_matches);
      
      $differences = array();
      
      foreach ($tmp_matches as $some_match)
      {
        $differences += array_diff_assoc($first_match, $some_match);
      }
      
      $identical = array_diff_key($first_match, $differences);
      
      $prepared_matches = array();
      
      foreach ($matches as $i => $some_match)
      {
        $prepared_matches[self::COMPRESSION_PATTERN_START . implode(self::COMPRESSION_PATTERN_DELIMITER, array_diff_assoc($some_match, $identical))] = $i;
      }
      
      $pattern_parts = explode('(\d)', $pattern);
      
      foreach ($identical as $position => $value)
      {
        $pattern_parts[$position + 1] = $pattern_parts[$position] . $value . $pattern_parts[$position + 1];
        unset($pattern_parts[$position]);
      }
      
      $pattern = implode('(\d)', $pattern_parts);
      
      return $prepared_matches;
    }
protected function deduplicateCompressionPattern($matches, &$pattern)
    {
      $tmp_matches = $matches;
      
      $first_match = array_shift($tmp_matches);
      
      $differences = array();
      
      foreach ($tmp_matches as $some_match)
      {
        $differences += array_diff_assoc($first_match, $some_match);
      }
      
      $identical = array_diff_key($first_match, $differences);
      
      $prepared_matches = array();
      
      foreach ($matches as $i => $some_match)
      {
        $prepared_matches[self::COMPRESSION_PATTERN_START . implode(self::COMPRESSION_PATTERN_DELIMITER, array_diff_assoc($some_match, $identical))] = $i;
      }
      
      $pattern_parts = explode('(\d)', $pattern);
      
      foreach ($identical as $position => $value)
      {
        $pattern_parts[$position + 1] = $pattern_parts[$position] . $value . $pattern_parts[$position + 1];
        unset($pattern_parts[$position]);
      }
      
      $pattern = implode('(\d)', $pattern_parts);
      
      return $prepared_matches;
    }
protected function deduplicateCompressionPattern ( $ matches , & $ pattern ) { $ tmp_matches = $ matches ; $ first_match = array_shift ( $ tmp_matches ) ; $ differences = array ( ) ; foreach ( $ tmp_matches as $ some_match ) { $ differences += array_diff_assoc ( $ first_match , $ some_match ) ; } $ identical = array_diff_key ( $ first_match , $ differences ) ; $ prepared_matches = array ( ) ; foreach ( $ matches as $ i => $ some_match ) { $ prepared_matches [ self :: COMPRESSION_PATTERN_START . implode ( self :: COMPRESSION_PATTERN_DELIMITER , array_diff_assoc ( $ some_match , $ identical ) ) ] = $ i ; } $ pattern_parts = explode ( '(\d)' , $ pattern ) ; foreach ( $ identical as $ position => $ value ) { $ pattern_parts [ $ position + 1 ] = $ pattern_parts [ $ position ] . $ value . $ pattern_parts [ $ position + 1 ] ; unset ( $ pattern_parts [ $ position ] ) ; } $ pattern = implode ( '(\d)' , $ pattern_parts ) ; return $ prepared_matches ; }
That looks complicated...

All numbers are taken out into $matches, so we check if any of those numbers are identical
in all the $matches and if they are we restore them to the $pattern, removing from the $matches.
This gives us patterns with "(\d)" only in places that differ for some matches.

@param array $matches
@param string $pattern

@return array of $matches
That looks complicated ...