在在线正则表达式测试器中工作的 MariaDB 正则表达式在 SELECT WHERE REGEXP 中不起作用 [英] MariaDB regex working in online regex testers does not work in SELECT WHERE REGEXP

查看:8
本文介绍了在在线正则表达式测试器中工作的 MariaDB 正则表达式在 SELECT WHERE REGEXP 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我得到的数据集格式不正确 EG fullName 列并且没有名称细分'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆