#1139-从正则表达式中得到错误“重复运算符操作数无效" [英] #1139 - Got error 'repetition-operator operand invalid' from regexp
问题描述
使用正则表达式从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使用Henry Spencer的正则表达式实现,旨在符合POSIX 1003.2
MySQL uses Henry Spencer's implementation of regular expressions, which is aimed at conformance with POSIX 1003.2 POSIX正则表达式不支持将问号 POSIX regexes don't support using the question mark 看起来您只需要使用贪婪的版本,该版本仍然可以使用.为避免与 It looks like you'll just have to use the greedy version, which should still work. To avoid the matching of things like 注意: Note: The 这篇关于#1139-从正则表达式中得到错误“重复运算符操作数无效"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
?
用作非-星形的贪婪(惰性)修饰符,以及PCRE(与Perl兼容的正则表达式)之类的加号.这意味着您不能使用+?
和*?
?
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">
之类的事物匹配,可以使用否定的字符类:<img style="/*some style*/" src="a.png"> <script src="www.example.com/js/abc.js">
, you can use a negated character class:'<img[^>]*src="http://www'
"
不必转义,并且隐含开头的.*
."
doesn't have to escaped and the .*
at the beginning is implied.