php preg_match(): 未找到结束分隔符 '^'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16129972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
preg_match(): No ending delimiter '^' found
提问by Simpel
Warning: preg_match(): No ending delimiter '^' found in .../functions/validations.php on line 29
警告:preg_match():在第 29 行的 .../functions/validations.php 中找不到结束分隔符“^”
The code:
编码:
if (preg_match($mail_pat, $email, $components)) {
What and where do I make the edit?
我在哪里进行编辑?
回答by din din
Perl based regex should be inside the delimeters.. "/your regex here/"
.. the deprecated POSIX regex were the one which did not require any delimeter.. eg ereg(")
基于 Perl 的正则表达式应该在分隔符内...... "/your regex here/"
.. 不推荐使用的 POSIX 正则表达式是不需要任何分隔符的......例如 ereg(")
回答by alexn
You must add delimiters to your regex:
您必须在正则表达式中添加分隔符:
if (preg_match('/' . $mail_pat . '/', $email, $components)) {
$mail_pat starts with a ^
but ends with another character, which causes the error since there are no matching delimiters.
$mail_pat 以 a 开头^
但以另一个字符结尾,这会导致错误,因为没有匹配的分隔符。