public static function glob_to_regex($glob)
  {
    $first_byte = true;
    $escaping = false;
    $in_curlies = 0;
    $regex = '';
    for ($i = 0; $i < strlen($glob); $i++)
    {
      $car = $glob[$i];
      if ($first_byte)
      {
        if (self::$strict_leading_dot && $car != '.')
        {
          $regex .= '(?=[^\.])';
        }

        $first_byte = false;
      }

      if ($car == '/')
      {
        $first_byte = true;
      }

      if ($car == '.' || $car == '(' || $car == ')' || $car == '|' || $car == '+' || $car == '^' || $car == '$')
      {
        $regex .= "\\$car";
      }
      else if ($car == '*')
      {
        $regex .= ($escaping ? "\\*" : (self::$strict_wildcard_slash ? "[^/]*" : ".*"));
      }
      else if ($car == '?')
      {
        $regex .= ($escaping ? "\\?" : (self::$strict_wildcard_slash ? "[^/]" : "."));
      }
      else if ($car == '{')
      {
        $regex .= ($escaping ? "\\{" : "(");
        if (!$escaping) ++$in_curlies;
      }
      else if ($car == '}' && $in_curlies)
      {
        $regex .= ($escaping ? "}" : ")");
        if (!$escaping) --$in_curlies;
      }
      else if ($car == ',' && $in_curlies)
      {
        $regex .= ($escaping ? "," : "|");
      }
      else if ($car == "\\")
      {
        if ($escaping)
        {
          $regex .= "\\\\";
          $escaping = false;
        }
        else
        {
          $escaping = true;
        }

        continue;
      }
      else
      {
        $regex .= $car;
        $escaping = false;
      }
      $escaping = false;
    }

    return "#^$regex$#";
  }
public static function glob_to_regex($glob)
  {
    $first_byte = true;
    $escaping = false;
    $in_curlies = 0;
    $regex = '';
    for ($i = 0; $i < strlen($glob); $i++)
    {
      $car = $glob[$i];
      if ($first_byte)
      {
        if (self::$strict_leading_dot && $car != '.')
        {
          $regex .= '(?=[^\.])';
        }

        $first_byte = false;
      }

      if ($car == '/')
      {
        $first_byte = true;
      }

      if ($car == '.' || $car == '(' || $car == ')' || $car == '|' || $car == '+' || $car == '^' || $car == '$')
      {
        $regex .= "\\$car";
      }
      else if ($car == '*')
      {
        $regex .= ($escaping ? "\\*" : (self::$strict_wildcard_slash ? "[^/]*" : ".*"));
      }
      else if ($car == '?')
      {
        $regex .= ($escaping ? "\\?" : (self::$strict_wildcard_slash ? "[^/]" : "."));
      }
      else if ($car == '{')
      {
        $regex .= ($escaping ? "\\{" : "(");
        if (!$escaping) ++$in_curlies;
      }
      else if ($car == '}' && $in_curlies)
      {
        $regex .= ($escaping ? "}" : ")");
        if (!$escaping) --$in_curlies;
      }
      else if ($car == ',' && $in_curlies)
      {
        $regex .= ($escaping ? "," : "|");
      }
      else if ($car == "\\")
      {
        if ($escaping)
        {
          $regex .= "\\\\";
          $escaping = false;
        }
        else
        {
          $escaping = true;
        }

        continue;
      }
      else
      {
        $regex .= $car;
        $escaping = false;
      }
      $escaping = false;
    }

    return "#^$regex$#";
  }
public static function glob_to_regex ( $ glob ) { $ first_byte = true ; $ escaping = false ; $ in_curlies = 0 ; $ regex = '' ; for ( $ i = 0 ; $ i < strlen ( $ glob ) ; $ i ++ ) { $ car = $ glob [ $ i ] ; if ( $ first_byte ) { if ( self :: $ strict_leading_dot && $ car != '.' ) { $ regex .= '(?=[^\.])' ; } $ first_byte = false ; } if ( $ car == '/' ) { $ first_byte = true ; } if ( $ car == '.' || $ car == '(' || $ car == ')' || $ car == '|' || $ car == '+' || $ car == '^' || $ car == '$' ) { $ regex .= "\\$car" ; } else if ( $ car == '*' ) { $ regex .= ( $ escaping ? "\\*" : ( self :: $ strict_wildcard_slash ? "[^/]*" : ".*" ) ) ; } else if ( $ car == '?' ) { $ regex .= ( $ escaping ? "\\?" : ( self :: $ strict_wildcard_slash ? "[^/]" : "." ) ) ; } else if ( $ car == '{' ) { $ regex .= ( $ escaping ? "\\{" : "(" ) ; if ( ! $ escaping ) ++ $ in_curlies ; } else if ( $ car == '}' && $ in_curlies ) { $ regex .= ( $ escaping ? "}" : ")" ) ; if ( ! $ escaping ) -- $ in_curlies ; } else if ( $ car == ',' && $ in_curlies ) { $ regex .= ( $ escaping ? "," : "|" ) ; } else if ( $ car == "\\" ) { if ( $ escaping ) { $ regex .= "\\\\" ; $ escaping = false ; } else { $ escaping = true ; } continue ; } else { $ regex .= $ car ; $ escaping = false ; } $ escaping = false ; } return "#^$regex$#" ; }
Returns a compiled regex which is the equiavlent of the globbing pattern.

@param  string glob pattern
@return string regex
Returns a compiled regex which is the equiavlent of the globbing pattern .