警告:preg_match() [function.preg-match]:未知修饰符 '(' in

发布于 2024-11-29 09:24:47 字数 565 浏览 0 评论 0原文

当我尝试验证用户名时收到此错误消息。以下 pregexp 字符串是这样的: ^([a-zA-Z])[a-zA-Z_-]*[\w_-]*[\S]$|^([a-zA-Z] )[0-9_-]*[\S]$|^[a-zA-Z]*[\S]$^。我已经尝试了我能想到的一切,但没有任何效果。

以下是我尝试过但失败的可能解决方案:

^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^
/^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^/
~^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^~
#^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^#

我希望你能帮助我。 提前致谢。

I get this error message when I trying to validate a username. The following pregexp string is this: ^([a-zA-Z])[a-zA-Z_-]*[\w_-]*[\S]$|^([a-zA-Z])[0-9_-]*[\S]$|^[a-zA-Z]*[\S]$^. I have tried everything I can think of, but nothing works.

These are the following possible solutions I have tried, but fails:

^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^
/^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^/
~^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^~
#^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^#

I hope you can help me.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2024-12-06 09:24:47

您的正则表达式以 ^ 开头,因此这被解释为 分隔符

多个字符之后,您的正则表达式将在其中包含 ^,并且由于它是未转义的,因此它被解释为正则表达式的模式部分的结尾。

紧接着第二个 ^ 之后,正则表达式将包含 (。在 preg_match 中,结束分隔符之后的任何内容都被解释为 修饰符,并且 ( 不是 修改。

要修复它,您需要 的 PHP 手册页。

阅读有关分隔符 像这样的事情:

/^([a-zA-Z])[a-zA-Z_-]*[\w_-]*[\S]$|^([a-zA-Z])[0-9_-]*[\S]$|^[a-zA-Z]*[\S]$/

在您的第一个示例中,您似乎忘记添加任何分隔符,并且 ^ 并不是作为分隔符在您添加了分隔符的后续示例中。没有告诉我们这些有什么问题是(也许它们应该是不同的问题?)。

Your regular expression starts with a ^, so this is being interpreted as a delimiter.

A number of characters later, your regular expression then contains a ^ within it, and since this is unescaped, it is being interpreted as the end of the pattern part of the regular expression.

Immediately after the second ^, your regular expression then contains a (. In preg_match, anything after the closing delimiter is interpreted as a modifier, and ( is not a modifier.

To fix it, you need to read the PHP manual page on delimiters.

I would assume you want something like this:

/^([a-zA-Z])[a-zA-Z_-]*[\w_-]*[\S]$|^([a-zA-Z])[0-9_-]*[\S]$|^[a-zA-Z]*[\S]$/

In your first example, it looks like you've forgotten to add any delimiters, and the ^ was not intended as a delimiter. In the subsequent examples where you have added delimiters, you haven't told us what the problems with those are (maybe they should be different questions?).

才能让你更想念 2024-12-06 09:24:47
 #^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^#

您遇到的问题是 [\/S]。这会强制用户名以 S 或正斜杠 / 结尾。您的意思是在那里写 [\S] 。 (尽管我不确定这样做的目的是什么。这将允许末尾有任何非空格字符。)

 #^([a-zA-Z])[a-zA-Z_-]*[\/w_-]*[\/S]$|^([a-zA-Z])[0-9_-]*[\/S]$|^[a-zA-Z]*[\/S]$^#

The problem you have is with [\/S]. This forces the usernames to end in S or a forward / slash. You meant to write [\S] there. (Albeit I'm not sure what the purpose of that is. That would allow any non-space character at the end.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文