Symfony Validation error: preg_match(): Compilation failed: range out of order in character class at offset

Symfony Validation error: preg_match(): Compilation failed: range out of order in character class at offset

当我验证从 Symfony 2.x 更新到 Symfony 4.4 的应用程序的操作时,出现以下错误。
我正在验证的功能是输入id“!”进行验证并确认验证工作正常。半角字母数字字符、下划线 (_)、连字符 (-) 和点 (.) 可用于目标区域。
有什么你能想到的吗?
我删除了form.errors,但是没有用。

错误

preg_match(): Compilation failed: range out of order in character class at offset 13

类型

                $form->add("loginId", TextType::class, array(
                   "required" => false,
                ));

         $resolver->setDefaults(array(
             'validation_groups' => function (FormInterface $form) {
                 $options = $form->getConfig()->getOptions();
                 $loginStaff = $options["login_staff"];
                 $staff = $form->getData();
                 return $this->getValidationGroups($loginStaff, $staff);
             },
         ));
     private function getValidationGroups($loginStaff, $staff)
     {
         $validationGroups = array();
         if ($loginStaff->isManage()) {
             $validationGroups[] = 'manage';
         }
 
         if ($loginStaff->isHq()) {
             if ($staff->getPassword()) {
                 $validationGroups[] = 'hqEdit';
             } else {
                 $validationGroups[] = 'hqNew';
             }
         } else {
             if ($staff->getPassword()) {
                 $validationGroups[] = 'shopEdit';
             } else {
                 $validationGroups[] = 'shopNew';
             }
         }
 
         return $validationGroups;
     }

validation.yaml

    getters:      
        loginId: 
            - Length: { max: 20, groups: [hqInitialSetting, shopInitialSetting, hqEdit, shopEdit] } 
            - Regex:        
                pattern: "/^[a-zA-Z0-9_-.]+$/" 
                groups: [hqInitialSetting, shopInitialSetting, hqEdit, shopEdit]

Staff.php

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use AppBundle\Model\Lib\Parameters;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\UserInterface;
 /**
 *
 * @ORM\Entity(repositoryClass="AppBundle\Model\Repository\StaffRepository")
 * @ORM\Table(name="staff", uniqueConstraints={
 *      @ORM\UniqueConstraint(name="idx_staff_unique", columns={"staff_login_id"}),
 *      @ORM\UniqueConstraint(name="idx_image_mail_unique", columns={"image_mail"})
 * })
 * @ORM\HasLifecycleCallbacks
 */
class Staff implements AdvancedUserInterface, \Serializable, EquatableInterface
{
    /**
     * @ORM\Column(name="login_id", type="string", length=20, nullable=true, options={"comment"="ID"})
     */
    protected $loginId;

树枝

    {{ form_start(form) }}

        {{ form_errors(form) }}
            <div class="formGroup">
                <div class="formGroup">
                    {{ form_label(form.loginId, 'LOGIN ID') }}
                    {{ form_widget(form.loginId) }}
                    {{ form_errors(form.loginId) }}
                </div>
        </div>
        {{ form_rest(form) }}
    {{ form_end(form) }}

我更改了正则表达式,它工作正常。
由于php版本升级,正则表达式方法可能已经改变。

pattern: "/^[a-zA-Z0-9-_.]+$/"