Search code examples
phpregexcakephpyiireference

PHP regex to find CR 3492161 or cr 3492161


I am trying a PHP regex to find CR 3492161 or cr 3492161. I have tried using the following regex however it is not working. Requesting your help. :-)

'CR\s/^\d{7}$/'
'CR\h/^\d{7}$/'
'CR /^\d{7}$/'

Note : CR is not a Carriage return, perhaps it is just a Pattern CR.

Code :

<?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();
    }
  }

Solution

  • You could try this:

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

    Regular expression visualization

    Debuggex Demo