Inheritance: extends DataType
 /**
  * The heart of the matter. This is where the selector gets to decide
  * on the inclusion of a file in a particular fileset.
  *
  * @param PhingFile $basedir base directory the scan is being done from
  * @param string $filename the name of the file to check
  * @param PhingFile $file PhingFile object the selector can use
  *
  * @throws BuildException
  *
  * @return bool whether the file should be selected or not
  */
 public function isSelected(PhingFile $basedir, $filename, PhingFile $file)
 {
     $this->validate();
     if ($file->isDirectory()) {
         return true;
     }
     if ($this->myRegExp === null) {
         $this->myRegExp = new RegularExpression();
         $this->myRegExp->setPattern($this->userProvidedExpression);
         if (!$this->casesensitive) {
             $this->myRegExp->setIgnoreCase(true);
         }
         $this->myExpression = $this->myRegExp->getRegexp($this->getProject());
     }
     $in = null;
     try {
         $in = new BufferedReader(new FileReader($file));
         $teststr = $in->readLine();
         while ($teststr !== null) {
             if ($this->myExpression->matches($teststr)) {
                 return true;
             }
             $teststr = $in->readLine();
         }
         $in->close();
         return false;
     } catch (IOException $ioe) {
         if ($in) {
             $in->close();
         }
         throw new BuildException("Could not read file " . $filename);
     }
 }
 /**
  * Parses parameters to add user defined regular expressions.
  */
 private function _initialize()
 {
     $params = $this->getParameters();
     if ($params !== null) {
         for ($i = 0; $i < count($params); $i++) {
             if (self::REGEXP_KEY === $params[$i]->getType()) {
                 $pattern = $params[$i]->getValue();
                 $regexp = new RegularExpression();
                 $regexp->setPattern($pattern);
                 array_push($this->_regexps, $regexp);
             }
         }
     }
 }
 /**
  * Sets the replacement string
  * 
  * @param string $string
  */
 public function setReplace($string)
 {
     $this->_regexp->setReplace($string);
 }
Beispiel #4
0
 */
class RegularExpression
{
    public static function isMail($email)
    {
        $result = filter_var($email, FILTER_VALIDATE_EMAIL);
        //验证成功返回邮箱,失败返回false,只要后边有.并符合域名要求,就算成功了。
        return $result;
    }
    public static function isUrl($url)
    {
        $result = filter_var($url, FILTER_VALIDATE_URL);
        return $result;
    }
    public static function isChineseCharacter($str)
    {
        $pattern = '/[u4e00-u9fa5]/';
        //        $pattern= '/a/';
        return preg_match($pattern, $str);
    }
    public static function isQq($qq)
    {
        $pattern = '/^[1-9][0-9]{4,}$/';
        return preg_match($pattern, $qq);
    }
}
var_dump(RegularExpression::isMail("_____@a_df.sdf"));
var_dump(RegularExpression::isUrl('http://www.baidu.com'));
var_dump(RegularExpression::isChineseCharacter('洪文'));
var_dump(RegularExpression::isQq("67788998"));