php 编译失败:在偏移 6 处无需重复

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8454564/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:45:40  来源:igfitidea点击:

Compilation failed: nothing to repeat at offset 6

phppreg-match

提问by smeddles24

im not sure why this wont work... works perfectly in multiple regexcheckers and testers. but when it comes to running it in PHPi get this error:

我不知道为什么这不起作用......在多个regex检查器和测试器中完美运行。但是在运行它时,PHP我收到此错误:

Warning: `preg_match()` [function.preg-match]: 
Compilation failed: nothing to repeat at offset 6 in /home/splose/public_html/index/index.php on line 49

im running this:

我正在运行这个:

if(preg_match('[\/^$.|?*+():<>]', $username)){}

回答by Nonym

Perhaps you can try to delimit your pattern?:

也许您可以尝试界定您的模式?:

if(preg_match('/[\/^$.|?*+():<>]/', $username)){}

Taken directly from the PHP Docs:

直接取自PHP 文档

Often used delimiters are forward slashes (/), hash signs (#) and tildes (~).

回答by yanwen li

I think you should use regex expression with delimiters forward slashes (/)

我认为您应该使用带有分隔符正斜杠 (/) 的正则表达式

// wrong pattern
$pattern = '[\/^$.|?*+():<>]';
// right pattern
$pattern = '/[\/^$.|?*+():<>]/';
if(preg_match($pattern, $username)){}