php - 如何验证正则表达式本身?
我需要验证用户输入,该输入可能是用于过滤他/她自己的应用程序中的字段的正则表达式,如何检查该正则表达式的有效性?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其传递到对
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.