PHP Regular Expressions: Delimiter Error
Issue:
When executing the following PHP code, an error is encountered:
$pattern = "^([0-9]+)$"; if (preg_match($pattern, $input)) echo "yes"; else echo "nope";
The error message reads: "Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in."
Investigation:
The error suggests that the regular expression pattern lacks an ending delimiter, denoted by the caret symbol "^".
Solution:
In PHP, regular expression strings require delimiters. To resolve the issue, enclose the pattern in delimiters:
$numPattern = "/^([0-9]+)$/";
Additional Considerations:
/^\d+$/
For further information, refer to the documentation on PHP Delimiters.
The above is the detailed content of Why Does My PHP `preg_match()` Function Throw a 'No Ending Delimiter' Error?. For more information, please follow other related articles on the PHP Chinese website!