在线正则表达式测试器中运行的MariaDB正则表达式在SELECT WHERE REGEXP中不起作用 [英] MariaDB regex working in online regex testers does not work in SELECT WHERE REGEXP
问题描述
我遇到了一个数据集,该数据集的格式为EG fullName
列格式不正确,并且没有名称细分,我想搜索任何名称以给定字母EG 'J'
开头的名称>
这是我的声明,但我只是抱怨意外的REGEXP
SELECT * FROM `Officers` WHERE `fullName` REGEXP '.*\sJ.*';
MariaDB中有什么方法可以做到这一点,不幸的是,名称不是固定的字数,有些只是2个名称,其他是6个名称,所以只有4个中间名称.
您可以使用
REGEXP '\\bJ'
^^^
在这里,\b
是一个单词边界,仅当J
前面没有字母,数字或_
时才会强制匹配.
\
被加倍,因为正则表达式引擎期望使用文字\
,并且需要两个反斜杠.
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.
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.
这篇关于在线正则表达式测试器中运行的MariaDB正则表达式在SELECT WHERE REGEXP中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!