MariaDB 正则表达式在在线正则表达式测试器中工作在 SELECT WHERE REGEXP 中不起作用 [英] MariaDB regex working in online regex testers does not work in SELECT WHERE REGEXP
问题描述
我遇到了一个问题,我以错误格式 EG fullName
列给出了一个数据集,并且没有名称细目分类 我想搜索任何名称以给定字母 EG 开头的位置'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'
这是我的声明,但我只是收到关于意外REGEXP
So this is my Statement but I just get complaints about unexpected REGEXP
SELECT * FROM `Officers` WHERE `fullName` REGEXP '.*sJ.*';
在 MariaDB 中是否有任何方法可以做到这一点,不幸的是,名称的字数不是固定的,有些只有 2 个名字,有些则是 6 个名字,因此有 4 个中间名.
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.
推荐答案
您可以使用
REGEXP '\bJ'
^^^
这里, 是一个单词边界,只有当
J
前面没有字母、数字或 _
时才会强制匹配>.
Here, the 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屋!