MariaDB regex working in online regex testers does not work in SELECT WHERE REGEXP

跟風遠走 提交于 2019-12-19 08:06:42

问题


I'm having a problem a dataset I have been given in bad format E.G fullName column and no breakdown of names I'm wanting to search where any of the names start with a given letter E.G 'J'

So this is my Statement but I just get complaints about unexpected REGEXP

SELECT * FROM `Officers` WHERE `fullName` REGEXP '.*\sJ.*';

Is there any way to do this in MariaDB, unfortunately, the names are not of a fixed word count some are only 2 names others are 6 names long so 4 middle names.


回答1:


You may use

REGEXP '\\bJ'
        ^^^

Here, the \b is a word boundary that will force a match only when J is not preceded with a letter, digit or _.

The \ is doubled because the regex engine expects a literal \, and two backslashes are required.




回答2:


Try using something like this:

SELECT * FROM `Officers` WHERE `fullName` REGEXP '[[:<:]]J'

See docs: https://dev.mysql.com/doc/refman/5.7/en/regexp.html



来源:https://stackoverflow.com/questions/46471187/mariadb-regex-working-in-online-regex-testers-does-not-work-in-select-where-rege

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