#1139 - 从正则表达式中得到错误“重复运算符操作数无效"

#1139 - Got error #39;repetition-operator operand invalid#39; from regexp(#1139 - 从正则表达式中得到错误“重复运算符操作数无效)
本文介绍了#1139 - 从正则表达式中得到错误“重复运算符操作数无效"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在使用正则表达式从 MySQL 表中选择一些结果时遇到问题.

I'm having trouble using a regular expression to select some results from my MySQL table.

我正在使用这个查询

SELECT text 
FROM `articles` 
WHERE content REGEXP '.*<img.*?src=\"http://www' 
ORDER BY date DESC

它说

#1139 - Got error 'repetition-operator operand invalid' from regexp

我用 Notepad++ 测试了正则表达式,它有效,为什么 MySQL 给我这个错误,我该如何解决?

I tested the regex with Notepad++ and it works, why MySQL is giving me this error and how can i fix it?

推荐答案

根据MySQL 手册

MySQL 使用 Henry Spencer 的正则表达式实现,旨在符合 POSIX 1003.2

MySQL uses Henry Spencer's implementation of regular expressions, which is aimed at conformance with POSIX 1003.2

POSIX 正则表达式不支持使用问号 ? 作为星号的非贪婪(懒惰)修饰符以及 PCRE(Perl 兼容正则表达式)等量词.这意味着你不能使用 +?*?

POSIX regexes don't support using the question mark ? as a non-greedy (lazy) modifier to the star and plus quantifiers like PCRE (Perl Compatible Regular Expressions). This means you can't use +? and *?

看起来你只需要使用贪婪的版本,它应该仍然有效.为了避免<img style="/*some style*/" src="a.png"><script src="www.example.com/js/abc.js">,可以使用否定字符类:

It looks like you'll just have to use the greedy version, which should still work. To avoid the matching of things like <img style="/*some style*/" src="a.png"> <script src="www.example.com/js/abc.js">, you can use a negated character class:

']*src="http://www'

注意:" 不必转义,开头的 .* 是隐含的.

Note: The " doesn't have to escaped and the .* at the beginning is implied.

这篇关于#1139 - 从正则表达式中得到错误“重复运算符操作数无效"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)