Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP正则表达式查找CR 3492161或CR 3492161_Php_Regex_Cakephp_Yii_Reference - Fatal编程技术网

PHP正则表达式查找CR 3492161或CR 3492161

PHP正则表达式查找CR 3492161或CR 3492161,php,regex,cakephp,yii,reference,Php,Regex,Cakephp,Yii,Reference,我正在尝试使用PHP正则表达式查找CR 3492161或CR 3492161。我已经尝试使用下面的正则表达式,但是它不起作用。请求您的帮助。:-) 注意:CR不是回车,可能只是一种模式CR 代码: <?php namespace Shedanigans; use Application\Filter\Linkify; class Module { public function onBootstrap() { Linkify::addCallback( func

我正在尝试使用PHP正则表达式查找CR 3492161或CR 3492161。我已经尝试使用下面的正则表达式,但是它不起作用。请求您的帮助。:-)

注意:CR不是回车,可能只是一种模式CR

代码:

<?php
namespace Shedanigans;
use Application\Filter\Linkify;
class Module
{
  public function onBootstrap()
  {
    Linkify::addCallback(
      function ($value, $escaper) {
        if (strcasecmp($value, 'CR\s/^\d{7}$/')) {
          // not a hit; tell caller we did not handle this one
          return false;
        }
        return '<a target="_new" href="https://xtz.abc.com/">'
               . $escaper->escapeHtml($value) . "</a>";
       },
      'CR\s/^\d{7}$/',
      strlen('CR\s/^\d{7}$/')
    );
  }
    public function getConfig()
    {
    return array();
    }
  }

strcasecmp
函数是二进制安全的不区分大小写的字符串比较,与regex没有关系。执行正则表达式检查的函数是
preg\u match

您应该尝试:
preg\u match('/^CR\s\d{7}$/i',$value)

这个正则表达式将接受CR字符串(不区分大小写)、一个空格和7个数字

试试这个表达式

preg_match('/^[Cc][Rr]\s[0-9]{7}$/', $value);
编辑: 仅限CR和CR非CR和非CR

preg_match('/^(CR|cr)\s[0-9]{7}$/', $value);
您可以在此处测试RegExr: 您可以尝试以下方法:

(?:CR|cr)\s[0-9]{7}


这也将验证
Cr 3492161
Cr 3492161
如果您可以将更改限制为^(Cr | Cr)\s[0-9]{7}当然是$
(?:CR|cr)\s[0-9]{7}