code: protected function filterByRegex($value, $rule)
      {
          if (!isset($rule['regex']) || empty($rule['regex'])) {
              return;
          }
  
          //如果你看到此行报错，说明提供的正则表达式不合法
          if (preg_match($rule['regex'], $value) <= 0) {
              throw new BadRequest(
                  T('{name} can not match {regex}',
                      ['name' => $rule['name'], 'regex' => $rule['regex']])
              );
          }
      }
docs: 进行正则匹配
  
  @param $value
  @param $rule
  @throws BadRequest