php - 如何验证正则表达式本身?

发布于 2024-10-13 00:12:39 字数 63 浏览 10 评论 0原文

我需要验证用户输入,该输入可能是用于过滤他/她自己的应用程序中的字段的正则表达式,如何检查该正则表达式的有效性?

I need to validate user input that might be a regular expression for filtering fields in his/her own application, how can I check the validity of that regex?

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

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

发布评论

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

评论(1

弃爱 2024-10-20 00:12:39

将其传递到对 preg_match() 的虚拟调用中,并查看它是否返回 false(指示错误)?

注意:: 根据您打算运行此应用程序的位置,我会对允许用户执行此操作的决定提出质疑。您可能正在为自己设置拒绝服务攻击;恶意用户所需要做的就是提供一个非常长且复杂的正则表达式字符串,然后您的服务器就会停止运行。

Pass it into a dummy call to preg_match(), and see if it returns false (indicating an error)?

Note:: Depending on where you intend this application to be run, I would question the decision to allow users to do this. You could be setting yourself up for a denial-of-service attack; all a malicious user needs to do is provide an incredibly long, complicated regex string, and your server will grind to a halt.

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