How to write a regex lookahead/lookbehind in mysql

僤鯓⒐⒋嵵緔 提交于 2019-12-21 13:32:13

问题


I'm trying to do something like

SELECT * FROM table WHERE column REGEXP (abc)(?=def)

and I got the error

Got error 'repetition-operator operand invalid' from regexp

due to the '?' -> see #1139 - Got error 'repetition-operator operand invalid' from regexp

Is there an equivalent in mysql that I don't see in https://dev.mysql.com/doc/refman/5.7/en/regexp.html ?

or maybe another mysql function that I don't know yet?


回答1:


MySQL REGEXP does not support lookaheads, but you can try to achieve the same logic using something like this:

WHERE column LIKE 'abc%' AND
      SUBSTRING(column, INSTR(column, 'abc') + 3, 3) <> 'def'


来源:https://stackoverflow.com/questions/39726749/how-to-write-a-regex-lookahead-lookbehind-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!