Delimiter must not be alphanumeric, backslash, or NUL byte

Description

The first character of a regex is the delimiter, that delimits the regex. There is a first and a last delimiter.

In the case of this error, the first regex character is of invalid type. It cannot be alphanumeric (a-z, A-Z and digits), the backslash \ nor the nul byte chr(0).

Note that if the first characters are white spaces, such as space, tabulation, new line, they are ignored as potential delimiter.

Example

<?php

preg_match('a[bc]a', 'abc');

?>

Solutions

  • Use a non-alphanumeric character, like /, #.

See Also

In previous PHP versions, this error message used to be Delimiter must not be alphanumeric, backslash, or NUL.