本文介绍了一切,但一切之间[和]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图匹配一切,但是[和]之间的一切。



[和]之间的一切都是

  \ [。+ \] 

一切,但是[和]之间的一切都是

  [^(\ [。+ \])] + 

搜索文本是

 有效[REGEX_EMAIL | REGEX_PASSWORD | REGEX_TEST] 

它与valid和REGEX_EMAIL | REGEX_PASSWORD | REGEX_TEST。



它应该匹配有效,而不是REGEX_EMAIL | REGEX_PASSWORD | REGEX_TEST。



如何解决?



我想要我的php验证类像CodeIgniter一样...

解决方案

根据您使用的数据尝试此操作[有效[REGEX_EMAIL | REGEX_PASSWORD | REGEX_TEST]]

  ^ [^ [] + 

它将返回有效 / p>

根据您使用的语言,您可能需要转义[,因此像这样写 ^ [^ \ [] +



这个正则表达式假定在[REGEX_EMAIL | REGEX_PASSWORD | REGEX_TEST]

$之前的文本中永远不会有[ b
$ b

我使用Eric Gunnerson的RegexWorkbench for .NET测试了这一点。


I'm trying to match everything, but everything between [ and ].

everything between [ and ] is

\[.+\]

everything, but everything between [ and ] is

[^(\[.+\])]+

The search text is

valid[REGEX_EMAIL|REGEX_PASSWORD|REGEX_TEST]

It matches "valid" and "REGEX_EMAIL|REGEX_PASSWORD|REGEX_TEST".

It is supposed to match "valid", but not "REGEX_EMAIL|REGEX_PASSWORD|REGEX_TEST".

How to solve?

I want my php validation class to be like the CodeIgniter one...

解决方案

Try this based on the data you're using 'valid[REGEX_EMAIL|REGEX_PASSWORD|REGEX_TEST]'

^[^[]+

It will return "valid".

Depending no the language you're using, you might need to escape the [, so write it like this ^[^\[]+

This regex assumes that there will never be a "[" in the text preceding [REGEX_EMAIL|REGEX_PASSWORD|REGEX_TEST]

I tested this using Eric Gunnerson's RegexWorkbench for .NET

这篇关于一切,但一切之间[和]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 02:39