php - how to validate a regular expression itself?

穿精又带淫゛_ 提交于 2019-12-19 07:49:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4747347/php-how-to-validate-a-regular-expression-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!