3

メッセージ:パターン「(http://)?(www。)?(youtu)((be.com)|(.be))/.*」の使用中に内部エラーが発生しました

$element = new Zend_Form_Element_Text($this->name);
$element->setRequired(true)
        ->setLabel(FileTypes::$names[$this->fileType])
        ->setDescription('Paste YouTube link here')
        ->setDecorators(FormDecorators::$simpleElementDecorators)
        ->addValidator('regex', false, '(http://)?(www\.)?(youtu)((be\.com)|(\.be))/.*');

単純な正規表現でもエラーをスローします。

4

3 に答える 3

1

正規表現が正しいことを検証しましたか?正規表現ツールで試して、エラーが発生するかどうかを確認してください。まともなツールは、正規表現が無効な場合になぜ間違っているのかを教えてくれるはずです。

私が見たほとんどの正規表現は、通常、ある種の文字、通常は「/」で予約されています。あなたのものではないという事実は、あなたが得ているエラーと関係があるかもしれません。

PHPの正規表現はPerlに似ていますが、いくつかの違いがあることにも注意してください。この場合、それらはおそらく問題ではありませんが、それでも注意する必要があります。 http://www.php.net/manual/en/reference.pcre.pattern.differences.php

于 2012-07-13T07:33:19.597 に答える
0

これを試してください。パターンを配列に入れ、区切り文字を含める必要があります。

$element = new Zend_Form_Element_Text($this->name);
                $element->setRequired(true)
                        ->setLabel(FileTypes::$names[$this->fileType])
                        ->setDescription('Paste YouTube link here')
                        ->setDecorators(FormDecorators::$simpleElementDecorators)
                        ->addValidator('regex', false, array(
                           'pattern' => '/(http://)?(www\.)?(youtu)((be\.com)|(\.be))/.*/'                                                                    
                         ));
于 2012-07-13T08:01:50.507 に答える
0

httpでスラッシュをエスケープします。

->addValidator('regex', false, '(http:\/\/)?(www\.)?(youtu)((be\.com)|(\.be))\/.*');
于 2015-02-12T20:14:36.543 に答える