正则表达式的正则表达式? [英] Regular expression for regular expressions?

查看:244
本文介绍了正则表达式的正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
是否存在用于检测有效正则表达式的正则表达式?
用于查找正则表达式的正则表达式?

Possible Duplicate:
Is there a regular expression to detect a valid regular expression?
Regular expression for finding a regular expression?

我有一个允许用户输入正则表达式的应用程序.我该如何检查正则表达式的任何输入并确保它们是有效的,因为如果不存在它们,则会出现preg_match错误?

I have an application that enables the user to input a regular expression. How do I check against any input of regular expressions and make sure they are valid ones, because if they are not there there will be preg_match errors?

我不想在preg_match之前使用'@',所以如果有一种方法可以检查正则表达式的用户输入的有效性,那么就很好.

I don't want to use the '@' before preg_match, so if there's a way to check the validity of the user input of regular expressions that'd be great.

PHP的正则表达式系统似乎过于复杂,以至于我无法为其提供正则表达式.

The regular expression system of PHP seems to be rather too complicated for me to come up with a regular expression for them.

推荐答案

preg_match()返回FALSE.

  1. 将表达式发送到服务器
  2. preg_match在空字符串上
  3. 查看是否发生错误
  1. send the expression to the server
  2. preg_match on an empty string
  3. see if an error occurs

您可以使用Ajax进行实时验证,也可以在提交表单后进行验证.
您也可以尝试通过将表达式提供给javascript regexp引擎来进行验证,但js regexp语法与php并非100%兼容.

You can either use Ajax to validate real time, or validate after form submit.
You can also try to validate by feeding the expression to javascript regexp engine, but js regexp syntax is not 100% compatible with the php one.

这篇关于正则表达式的正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆