在mysql中取反正则表达式模式 [英] negate regex pattern in mysql

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

问题描述

可以否定Mysql中的正则表达式模式吗?我知道通常我们可以使用?!取消模式,但这在Mysql中不起作用.

It is possible to negate a regex pattern in Mysql? I know that normally we can negate a pattern using ?!, but this does not work in Mysql.

我需要达到的结果是否定与某些二进制文件(如.0.0..0.)匹配的结果,这意味着当第二,第四和第七为零时不要计数.我不能使用NOT REGEX,因为我正在构建mysql过程,该过程应与其他条件一起使用.

What I need to acheive is to negate the result matching some binary like .0.0..0., which means don't count when second, fourth and seventh are Zeros. I can not use NOT REGEX, because I am building the mysql procedure, which expected to be used with other condition.

任何想法都值得赞赏,非常感谢.

Any idea is appreciated, thanks a lot.

推荐答案

几乎所有负正则表达式"匹配问题都有一个通用解决方案:使用某种逻辑将其转化为正匹配问题.

There is a general solution to nearly all "negative regex" matching questions: turn it into a positive matching problem using some logic.

这通常比尝试构造匹配除此模式外的所有内容"的正则表达式容易.

This is usually easier than trying to construct a regex that matches "everything but this pattern".

在这种情况下,这很简单:

In this case, that is quite simple:

select * from table
    where column_name regex '[pattern]' = 0 

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

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