Search code examples
phpregexdelimiter

Regex error: Delimiter must not be alphanumeric or backslash


I am trying to grab the articleId which is formatted as follows:

articleId=1234567

Here is the code I am using

$regex = 'articleId\=[0-9]{7}';
preg_match_all($regex, $data, $match);
for ($i = 0; $i < count($match[0]); $i++) {
    echo "" . $match[1][$i] . "]";
}

I am receiving the following error:

preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash

I am using PHP 5.2.17


Solution

  • place delimiters in your regexp, like this:

    $regex = '/articleId=[0-9]{7}/';
    

    also, there is no need to escape equal sign